Smooth Linear Motion in Scripting - Tutorial (Written)

Discussion in 'Halo and Forge Discussion' started by ExTerrestr1al, Oct 28, 2017.

  1. ExTerrestr1al

    ExTerrestr1al Forerunner
    Senior Member

    Messages:
    2,387
    Likes Received:
    2,515
    How to: Achieve Smooth Scripted Linear Motion in Halo 5's Forge


    This is intended as a guide for the video tutorial here, where I discuss the topic and visually show each script, but do not go into great detail on all aspects. Here is a demo map you can load up in Forge or Customs.

    If you don't require any of the scripting background or tips, proceed to "How to Implement"

    Background: (These component concepts are combined in the implementation of smooth motion)
    Basic Scripted Motion, and why it sucks:

    The simplest form of scripted linear motion is to place a script on an object and directly instruct it to move X units on one of three axes over a period of time.
    [​IMG]

    This is limited to 1000 units, which isn't usually an issue. Worst of all, is that the motion seems to hiccup or hesitate every 1/2 second or so. Depending on internet connection, it could be relatively smooth, or extremely unstable. It also seems unstable randomly for good connections.

    For this reason, many have avoided motion for most use-cases, or have implemented non-scripted workarounds for very confining types of motion. FOr instance, using grav sliders to push an object, which is best if only used at a distance since the grav sliding effect may not be what you have intended for player movement on your map.

    Improved, less confined motion: Timer, repeat Move/Offsets in smaller increments
    One of the main ways you can achieve scripted motion that is a little less confining, is to set up your Move/Offset script(s) to repeat frequently, chopping up a longer trip into smaller pieces. Furthermore, if you don't allow the script to finish each time, it may appear a little smoother than the most basic method mentioned above, but not always. You will still be very limited by this method.

    [​IMG][

    It should be noted though, that if you mean only to move a simple object at a large distance from view of the player, these methods may be sufficent, especially if you get the right combination of speed and distance.
    • Fast basic motion: Can appear smooth if the player's eye doesn't have a chance to notice the hesitation and it is properly spread out over a large distance.
    • Slow basic motion: can also appear smooth-ish due to the stuttering effect being compressed into many stutters in a smaller area.

    Anything outside of these confining restrictions will be very unattractive. Remember, we're talking about linear motion, not rotational motion.

    Basic Move/Offset actions can be placed in a script on the object being moved, or it can be placed on a script brain, with the Objects section specifying the object to move, which can be a label placed on the object.
    [​IMG] [​IMG]

    Because you are repeating motion, you need a means of initiating and ceasing the motion on cue. As in the tip above, you can use a brain to spawn in and out when you wish the movement to occur. On the movement script, make sure to always uncheck the option "Always Run" so the movement is not attempted while the brain is despawned. **If you wish to also have the brain despawned at the start of the match, you'll need to have a script specifically despawning all objects of a particular label, usually User Zulu.

    The discovery:
    I first noticed this might be possible when I created the "Eternity Ball: A Shield Drain Item" (thread pending) featured in @icyhotspartin 's map "Eternal Flame" which I co-forged on for the 1v1 contest. This was my first use of having an object continually follow another object. I noticed that the ring I have programmed to follow the ball in order to indicate its armed state (Red/Green) was following it rather smoothly and consistently. I concluded this was because I was telling it to repeat so frequently. That was only part of the answer to smooth motion, however. (An object following a spartan or a ball is smooth because the spartan and ball move smoothly)

    Timers can repeat at a minimum interval of .05 seconds. That's one 20th of a second. However, Move/Offsets can only be comlpeted in a minimum time of .10 seconds. That's double! While it would be nice to have .05 for movements as well, that is not the key here. The key is that this disparity sent me on the chase of what combination of numbers would make a smooth trip by interrupting it part way through. But again, that's only part of the answer.

    During this stage, I assumed the sweet spot might be around a few tenths from .10. Still, with only this one "layer" involved, it was never perfectly smooth, and very inconsistent.

    Next, I focused on the best way of moving complex objects, since they seemed to fly apart more easily. The shuttle I was moving was more than 64 pieces, which we'll talk about later on.

    After building that cage, I set up nav points for it to travel on. When it was choppy, I made it chase another object, and that seemed better, but not perfect. It wasn't perfect because I had not yet accidentally stumbled upon the solution.

    One day, as I was trying different variations of this, I set a new script where every .05 sec it tried to move a distance in 1.0 seconds. I had meant to make it .05 vs .1, not 1.0. This made all the difference, and is the key to smoothness.

    The combination of the fact that your destination keeps changing, and the fact that you are allowing a longer instruction to be interrupted only a fraction of the way through completing it, is what smooths out the motion.

    How to implement: Smooth Linear Motion

    Simply put, you can send an invisible "chase" object moving from point A to B and script your actual intended object to always follow that chase object closely. If combined with the technique of allowing that "constant follow" to be interrupted after a short portion of its movement is complete, we have the opportunity to smooth it out. By also creating a large disparity between the repeats of the motion and the allowed time for its completion, they combine for amazing effect!

    How two concepts work together - Realize that the chase object, whether it be an invis blocker or a script brain, which interacts with nothing (in theory), is still going to stutter as it moves. That's unavoidable at this first layer. However, because the other intended object's chasing behavior repeats at small intervals, the chance that any one repeat of it lands while the chase object is "out of line" so to speak, is smaller. But, when it happens, because we are also interrupting the action so early in its total time for completion, the unsmooth action is also smoothed out by only doing a small amount of it's "unsmooth" instructions. It is also only instructed to move to "unsmooth" coordinates for such a small amount of time that an observer would be hard-pressed to notice it. The overall line from A to B remains very smooth.

    The larger the disparity between the chase movement script, the smoother still. But the lag and delay of the movement of the intended object is increased. (Depending on your application, this valuel can be changed several 10ths or perhaps more)


    The Scripts
    (disregard script numbers)

    Constant Follow Script for Intended Object or Group - Instruct an object to target another object every X sec, taking Y amount of time. You can either place this script on your intended object, or you can first place a User label on that object and remotely instruct it to move via a Script Brain. This could either be always on, or turned on and off by despawning the script brain containing the instructions. Note, there are other logical means of selecting a target object other than simply placing a label on it.

    You can also offset the destination for your object by inputing coordinates in the X, Y, Z values. This can help you avoid hitting objects and align various things, but is not always necessary.
    [​IMG]

    Remember, part of our smoothness comes from the fact that we can set such a small interval for a repeat (.05) and that the overall trip is so much longer than that repeat interal (.80+). I have gone as low as .50 and it can be pretty smooth. Each application will vary in its numbers and precise settings.

    Setting the Objects and Targets - In this example, Object User Barvo needs to target Ojbect User Charlie.
    [​IMG] [​IMG]

    Move Chase object X units on one or more axes in Y amount of time - Using simple Move/Offset actions, decide what should trigger your movement (in this simple example in the video, Message Send Alpha was triggered by a simple switch, but there are countless other ways of triggering a motion event, or it can always be on as part of a dynamic map element)

    Again, this can be placed on the chase object or on the script brain you may already be using for this setup.

    [​IMG]

    ^^And that should be enough to get you some basic linear smooth motion!

    However, a lot of the time, you may want to implement something a little to a lot more complex. Do not limit yourself to simiplicity if doing something a little more special will make a huge difference!

    Motion Sequences

    Where this technique really shines is in the fact that it also smooths out changes in an object's velocity and direction. If you place a set of waypoints as either invis objects or brains with nothing but labels, and string those waypoints together in a sequence in a script that tells the chase object to move to point A,b,c, and d, you can tailor your specific flight path. Then, it is also useful to consider the amount of time/speed for each section of the journey. If you want a pelican to take off slowly, then it's first waypoint should be nearby and also be given a relatively long time to get there. However, for a longer and faster section of your trip, when the pelican is at cruising speed for instance, if you make it take a small amount of time to go a long distance, the pelican will speed up when that action occurs. But, it does not jerk into that new speed and direction. It transitions smoothly.

    Here is a still relatively simple, but more complex sequence as featured in the video. (dThere are countless other ways to set paths and provide instructions to the chase object.)

    Two Snips of same script with four Move/Offset actions, each sending the chase object to a different target. Each waypoint marker piece has its own User label. Use the example shown above for targeting a piece in a movement script. Make sure you are targeting each piece in the sequence in the correct order.
    [​IMG] [​IMG]

    If your sequence is limited to four or fewer waypoints, one script can be sufficient. However, you could set up much more lengthly sequences with several scripts. All subsequent scripts would either have a wait action before doing any of its own movements, or be triggered by something else. You could make a pelican first land, sit on a pad for a period of time, and then take off again!

    Moving objects in welded groups

    Selecting objects to move using groups
    One great method of selecting objects for any type of script can be through grouping items that all need to do the same thing, or by using grouping commands to do additive and subtractive selection of objects.

    Grouped movement is only possible for 64 items per scheme. You could double everything you're doing and get 128 objects, each moving as a 64 piece chunk of the larger object. But practically, this is limited to 64 piece objects.

    Rather than placing a movement script on each part of the larger group, we can give them all a label, say User Alpha. Even better, we can group them all together and add one line to the Selection of the Object in our script equal to "Grouped Siblings (Add)". Then, only the parent piece of the group needs a label. However, unfortunately, these pieces will all attempt to follow the same piece and move to the same point.


    The solution is to weld your group so the game sees it as a single piece. You must also use the "Group Add SIblings" etc to make sure the entire contraption is included. To clarify, since you are welding, you shouldn't need to add the "Grouped Siblings (Add)" line to your Movement Objects list as with just grouping alone. The physics should just carry the whole group due to the weld. But you must have the parent object fixed with a label prior to the weld. Not True - use grouping logic as indicated above.

    Your welded group does not need to be set to Normal physics as you may assume. The pelican example in the video is kept at phased physics the entire time! However, depending on the behavior and characteristics of your objects, you may desire to change the physics during the sequence of movements. For instance, turn off the "constant follow" behavior of a ship after it lands and switching its physics to Normal or Fixed physics so it seems to be truly resting on the ground.

    In this scenario remember the simple setup from earlier - all you need is a chase object for your welded group to always follow. Either the parent object or the brain targeting the parent piece via a user label, needs to tell it to always follow the chase object, which itself is told where and when to go to a destination.

    It's all very simple but there is a lot to talk about and explain for nuances of how you can tune your own use of this technique for whatever applications you can think of.

    Please comment below with questions and possible improvements for this tutorial.
     
    #1 ExTerrestr1al, Oct 28, 2017
    Last edited: Nov 5, 2017
    Blaze, AngelitoCO, Kawecki 22 and 9 others like this.
  2. a Chunk

    a Chunk Blockout Artist
    Forge Critic Wiki Contributor Senior Member

    Messages:
    2,670
    Likes Received:
    7,152
    This just looks like some sort of voodoo to me.
    Awesome job on this!
     
  3. ExTerrestr1al

    ExTerrestr1al Forerunner
    Senior Member

    Messages:
    2,387
    Likes Received:
    2,515
    THanks!

    it's not hard to do the basic pieces of it.

    feel free to play around on the demo map
     
  4. Shak T Goboree

    Shak T Goboree Forerunner
    Senior Member

    Messages:
    9
    Likes Received:
    7
    Congrats on finding this - I know a lot of people who are going to find it extremely useful.

    I'm looking forward personally to implementing this!
     
  5. Yumudas Beegbut

    Yumudas Beegbut Legendary
    Wiki Contributor Senior Member

    Messages:
    393
    Likes Received:
    352
    Oh man, so glad you've got this thing going! I gotta dig thru all this info.

    I like the kinda non-linear parts you do with slowing down and changing directions. We can take that further by having the chase object move sideways, closer, or further... stuff that makes the path and movement real dynamic.

    I guess rotation is still the problem child for us... I think rotation will be smoother if you mix it in with your technique. I believe the wobbling is based on the server sending our Xboxes position updates & the Xbox has this position correction smoothing function that needs to go away. But I think your technique causes constant updates which keeps things smoother and I hope rotation is included there. I have some rotation stuff worked out I can share in a bit.
     
    ExTerrestr1al likes this.
  6. ExTerrestr1al

    ExTerrestr1al Forerunner
    Senior Member

    Messages:
    2,387
    Likes Received:
    2,515
    Cool. Glad you find this useful. you definitely helped me unlock some of the scripting tidbits for other projects that probably lead me to eventually discover this, so thanks for being willing to share many months ago!

    I think you are correct about the networking aspect of why motion is inherently shaky, and yes because we are constantly interrupting and resetting the motion while at the same time constantly redefining how long the motion should be, makes those network handshakes happen at a different interval or just constantly.

    Rotation is a different beast for sure, but I have one technique, plus two other variations of it that I've found in other maps recently. My plan is to keep messing with them and make sure I fully understand ins and outs, and then make a new video.

    Let's collaborate on that one, shall we?
     
    Yumudas Beegbut likes this.
  7. Yumudas Beegbut

    Yumudas Beegbut Legendary
    Wiki Contributor Senior Member

    Messages:
    393
    Likes Received:
    352
    Holy crap I haven't gotten around to responding to this yet. I can't recall what we talked about before, but I'm glad you took out to the next level!

    I definitely wanna work on this stuff with you more... And the game mode stuff too. Just not sure what's a good way to do that since I don't know what day/time I'll be awake and in good enough shape to get stuff done. Sending messages back and forth works for me since there's no schedule needed.

    We can use Forgehub or discord or set up something new for everyone to jump in and help out if they want. I can also try to remember to show my XBL account as online when I can do stuff. Maybe if we write out all the stuff we need done and some ways we might be able to do them on Forgehub as a big community project we can get this stuff done & the game modes in H5 will explode in number.
     
    ExTerrestr1al and a Chunk like this.
  8. ExTerrestr1al

    ExTerrestr1al Forerunner
    Senior Member

    Messages:
    2,387
    Likes Received:
    2,515
    Simply Smooth Scripted Elevator - (simple automatic up down)

    FOr some reason, it's not giving me an edit button for the OP, but here is a link to a pre-fab that can be very easily swapped out for any piece you want, to make a SMOOOOTH elevator. I think a few people have implemented something like this since... good results!
     
    Yumudas Beegbut likes this.
  9. ZORO

    ZORO Spartan III

    Messages:
    15
    Likes Received:
    3
    Wow that’s great Ex. and right on time for what I’m building. My problem is that I’m not quiet as smart at scripting as some and I wish you could write out the entire script page and name the object that you’re applying it to. The movement is fine I just can’t get the chase ball and object down. Please help if you can please .
     
  10. ExTerrestr1al

    ExTerrestr1al Forerunner
    Senior Member

    Messages:
    2,387
    Likes Received:
    2,515
    Hi there. Quick question, are you the same guy asking the question on Discord, just for context? (SpazzterBeats)

    If not, then please write out what you are attempting to do and I will try to recommend the right technique for that specific application, as there are many variations we could go into.

    Forgehub doesn't allow me to edit old posts, so I'll have to clarify in new posts, here.
     
  11. ZORO

    ZORO Spartan III

    Messages:
    15
    Likes Received:
    3
    No Ex that's not me on discord. But my question was about the first three scripts of the six on linear motion. I simply need the follow the block scripts in just a little more detail. Simply said I need help with an object chasing the ball with a brain giving the script commands for the coordinates and time etc. using labels if that's the best way. This will be an aesthetic motion that goes under my map visual through the floor. When a player on another level performs a task something will happen aesthetically and operationally. I have most of the script figured out but this simple has me stumped. Please help if you can. Btw my GT is SpinalTap 325.
     
    #11 ZORO, Sep 26, 2019
    Last edited: Sep 28, 2019
    ExTerrestr1al likes this.
  12. ZORO

    ZORO Spartan III

    Messages:
    15
    Likes Received:
    3
    Hi Julian. Did I give you enough information? My plan is to have object moving across the map exactly as you did on the trains are doing on Stand Clear. Using move offset is too choppy and I’ve tried every time combination of time that I can think of and it’s still choppy. I’ve tried the Rabbit Chase method and that didn’t seem to work either like I intended for it to. Julian if you don’t have time please let me know.
     
  13. Yumudas Beegbut

    Yumudas Beegbut Legendary
    Wiki Contributor Senior Member

    Messages:
    393
    Likes Received:
    352
    Heya, @ZORO ! Sorry we're not keeping up with Forgehub threads here, but here's another smooth linear motion technique video Exterrestr1al made that works with phased objects... it sounds like this method might be the best for what ya need (It's supposed to jump to 3:06 where the scripts are):

    Aslo, here's a link to jump into the fray in the Scripter's Guild discord, which we're on every day so it's a lot easier to get more help for this: https://discord.gg/rSFqZ4C
     

Share This Page