r/forgescripting • u/burningrampage1 • Nov 13 '22
Tutorial - Move Object/Platform Between Two Points on repeat using "Translate Object to Point"
TLDR: Look at the attached image
So the first thing to note is that only objects which are set to 'dynamic' (as opposed to static) in the world, are able to be manipulated by scripts. And choose fixed or phased for the physics - to ensure it stays right way up and isn't bumped off course.
The next thing to find out is what are the vector coordinates that you want to move to and from, and how long you would like it to take.
Now, you can move onto scripting the platform (for the sake of simplicity, I assume you are only moving a single object, not multiple, and not a prefab - because those have issues).
If you haven't already then create a script brain, and go into the node graph (there are tutorials out there to catch you up to understanding this).
Before you go into the node graph, make sure you have your platform selected, and then once in the node graph, right click (idk what it is on xbox) and click 'add object reference', this allows us to choose the platform as the object we want to manipulate.
- First thing you want for scripting is an event, for moving an object back and forth on a loop, I believe an 'every N seconds' node will work well, so put that in there (events custom -> every N seconds).
- Then, you want to create 2 basic vector3's nodes (variables basic -> vector3), and fill in your before and after positions (x, y and z - find these in the forge world at the bottom of your screen).
- Next, put in two 'tranlate object to point' nodes (objects transform -> translate object to point), these will control the movement of your platform.
- Then, for good measure add a 'wait for N seconds' node (logic -> wait for N seconds), this will be the delay from when the platform reached the desired point to when it turns around and goes back.
- Finally, combine all of the diamonds in the corners of the nodes together so that you have:
event -> transform_1 -> wait -> transform 2.
Go to each node's properties and edit the following:
'Every N seconds event' -> seconds (set this to 1, or the same delay as the wait), intial delay (set this to how long from the game start to have this start moving).
'Translate object to point' (1&2) -> Duration in seconds (self explanatory), movement curve (set to linear if you don't have a preference), object (link the object reference to both of them), position (link the respective vector3s to the correct translate box).
'Wait for N seconds' -> seconds (set this to the same as the event, however long you want in between movements).
Go ahead and test this in play mode, and it should move between the two points. Note that it should be initially placed in the world at the position of the second vector3, so that it isn't initially out of place.
Also note, that it seems that in order to 'ride' on it, you either need some smart engineering, or a player has to move along with the platform while it moves - it doesn't move things that are on top of it.
If you don't understand how to do some of the things I mentioned above, then I recommend checking out some youtube tutorials to catch you up on the fundamentals of the scripting interface and whatnot.
In the end it should look something like this:

1
u/Artoriou Nov 13 '22
Pretty cool, how would you go about allowing players to move with the object?
1
u/Acolytis Nov 13 '22
Now I just need you to teach me how to get an object to rotate on a point continuously (like floating panels in a cube shape that never actually touch and rotating it around the center of all of them. But maybe I should weld them together and try that to give it a center point? But then would it still be a dynamic object? I gotta play around more or find a tutorial
1
u/jak4896 Nov 14 '22
So this is brilliant and helped me a lot. I'm trying to find a way to make it so the object stops when you're in proximity to it. However, it does not work... Here it is if anyone wants to take a crack at it.
3
u/hey-im-root Moderator Nov 13 '22
This is great work and very thorough. Adding it to the stickies posts now!
1
u/iMightBeWright Nov 13 '22
You mentioned the issues with prefab movement. I assume the answer is "no," but I have to ask:
Has anytime found a way, even if complicated, to move a prefab in phased physics over a duration of time? Best I can do is teleport instantly or move each individual piece one at a time.
This has to be unintended, either through a bug or some switch hasn't been flipped yet.
1
u/jak4896 Nov 13 '22
Thank you for your service
1
u/ihatethisplebsite Nov 28 '22
Does vector3 really have a limit of xyz: 1,000? I'm trying to set my box to move at coordinates greater than 1,000.
0
u/[deleted] Nov 14 '22
[deleted] — view deleted comment