Search Unity

Simple Waypoint System (SWS) - Move objects along paths

Discussion in 'Assets and Asset Store' started by Baroni, Dec 10, 2011.

  1. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    Can I use this on a sphere? I need a simple system that will get A I pilots/Drivers to walk around a sphere , attack a base on a sphere and get into and out of vehicles I got an idea of making an A.I vehicle a a Major Node so they would alway either run back to their base or get into an empty vehicle
     
  2. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Simple Waypoint System provides tween based or Unity navmesh movement scripts.
    Tweens work in 3D space, since you just place the waypoints where you want them to be - with bezier controls you can even fine tune the curves. By design, tweens are fixed animations thus not suited for objects that wander around randomly.
    As far as I know, Unity's navmesh system cannot bake spheres, so that movement script would not fit your needs either.
     
  3. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    OK Thanks
     
  4. tengkufathullah

    tengkufathullah

    Joined:
    Apr 3, 2017
    Posts:
    14


    Take the ladybug as an example, it flip horizontally based on the direction it's going, but I also lock their x rotation(if I'm not mistaken). The issue is, after sometime, the ladybug will not flip horizontally thus it show that the ladybug moving backward because of fail flipping.
     
  5. yumianhuli1

    yumianhuli1

    Joined:
    Mar 14, 2015
    Posts:
    92
    118.png
    Hello,What about this two way points of Spline?And How to slove this jerk?Thank U!
     
  6. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    @tengkufathullah Honestly it is difficult to recognize something in this screenshot :) Did you enter the lookAhead value correctly, in the range of 0-1? How about the value 0.02?

    @yumianhuli1 The path is calculated by DOTween. If that happens, it usually means that your waypoints are too close to each other. E.g. because you have zoomed in too much or you simply placed too many of them in a very short distance.
     
  7. yumianhuli1

    yumianhuli1

    Joined:
    Mar 14, 2015
    Posts:
    92
    Hello,the distance is so far about 5 meters(units).
     
  8. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    @yumianhuli1 Could you contact the developer of DOTween regarding this issue? Alternatively, please send a minimal project (as a zip file) that reproduces this to our support email, and I will contact him on your behalf.
     
  9. yumianhuli1

    yumianhuli1

    Joined:
    Mar 14, 2015
    Posts:
    92
    I tested it, if I make a sample scene(just two points) that two points of spline is no problem.
    But when two points in the middle of some points, that jerk will happen!(the same position in two cases)
    Any solution or idea is ok!
     
  10. tengkufathullah

    tengkufathullah

    Joined:
    Apr 3, 2017
    Posts:
    14
    Below is a screenshot when the flip issue happen, I their z-rotation goes wrong when the flip issue happen.




    This is the setup for that yellow butterfly.



    It is not only that buttefly, but sometimes it happens to other bugs too.
     
  11. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Thanks @tengkufathullah. Since the path and flipping behavior is calculated by DOTween (SWS is not involved there), I am assuming that this happens at very sharp turns of your path, which could lead to the tween getting confused about its current movement direction. Does this also happen with more curved turns?

    In case curves, or the waypoint rotation feature I mentioned before, is not something you can work with - could you please send a very small project that reproduces this (maybe even in one of the SWS sample scenes) to our email, so we can take a close look at it and eventually contact DOTween's developer directly on your behalf.
     
  12. tengkufathullah

    tengkufathullah

    Joined:
    Apr 3, 2017
    Posts:
    14
    @Baroni Thanks for the explanation, I will try to modify the sharp turn if any(my designer does it). And will give you feedback regarding the progress.
     
  13. yumianhuli1

    yumianhuli1

    Joined:
    Mar 14, 2015
    Posts:
    92
    Hi! Support rigidbody walking along way points without constant speed?
     
  14. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Not sure what you mean by that. The splineMove movement script moves object by transform.position, not rigidbody forces. Also the navMove component is driven by Unity's navigation system. For non-constant speed you can define ease types, or change the object's speed at runtime e.g. in a coroutine over time.
     
  15. jk15

    jk15

    Joined:
    Jun 23, 2011
    Posts:
    49
    Hi,

    I'm doing a test. I've made an animation in Unity of a cube rotating around its X axis 90 degrees by adding a transform property via the Animation panel. I've also added the parameters Speed and Direction to the animation.

    I add SplineMove and MoveAnimator to the cube, and have assigned it a Path Container.

    My cube follows the path but there is no animation. If I remove the scripts it does animate.

    How do I get the animation to animate and follow the path? I'm sure I'm messing something simple up here! Thanks.
     
  16. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Hi @jk314,

    the MoveAnimator component gets the speed an direction from the movement script and passes them to an Animator component on your object. If you just let your object rotate via a Animation clip, then that's not something the MoveAnimator has control over. The Animator would need the animation clips defined as well.

    If you just would like to let your cube does its thing (e.g. rotate), it goes way simpler than that. Just make your rotating cube a child object of an empty game object. Then instead of on the cube, attach the splineMove script to the parent. This way your cube rotates locally while the parent is driven by the movement script.
     
  17. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    Hello. Is there an easy way to create a circle path in SWS?
     
  18. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Hi, the easiest way would be to create a "round" bezier path with 4 waypoints. Then for each waypoint, align its 2 control points horizontally. Like this:

    X = waypoint
    o = control point

    o ------ X ------ o
    I ------------------ I
    X ---------------- X
    I ------------------ I
    o ------ X ------ o

    This actually makes up the perfect circle.
     
    username132323232 likes this.
  19. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    477
    Thank you Baroni! I was also wondering if it's possible to write a "one-click" C# script that would do that?
     
  20. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Sure. Since waypoints are just game objects, you can position them via script as desired. Editor script or at runtime - both would work. For a runtime sample on how to create a path via code see the Runtime example scene (it has a sample for normal paths, not bezier paths, but you'll get the idea).
     
    username132323232 likes this.
  21. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    I have purchased this asset in the past, and now I'm wondering if it can be used to create a wiggle effect on a game object? I don't need my object to move however, I want the wiggle to occur in-place.

    Can SWS be used for my purpose?

    Thanks!
     
  22. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    @blamejane SWS is still a waypoint system, which does movement. If you would like to animate something in place you can just use DOTween.
     
  23. ChooChooBuckaroo

    ChooChooBuckaroo

    Joined:
    Oct 17, 2018
    Posts:
    8
    @Baroni

    I purchased SWS a couple months ago and have been able to slowly incorporate it successfully into my project. However, there is one feature I'm having trouble implementing with it and was hoping you could provide some guidance.

    Objective: Move object along a path by a user-given distance.

    Moving the object along the path on start or with a button click is not a problem. I've come close to solving my problem by modifying the following snippet from the PathInput demo, where carCount is the user-given distance that the object needs to move.
    Code (CSharp):
    1.  
    2. void Update()
    3.     {
    4.             float speed = speedMultiplier / 100f;
    5.             float duration = move.tween.Duration();
    6.            
    7.             progress += Time.deltaTime * 10 * speed;
    8.             progress = Mathf.Clamp(progress, 0, carCount);
    9.             move.tween.fullPosition = carCount;
    10. }
    The problem I've run into with this is that the object is immediately moved to the new position, there is no tween. Your help would be much appreciated.
     
  24. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Hello @richdunne,

    if you would like to let the object move "automatically" (via a tween) to a position on a path, then the PathInput demo is not the correct starting point. What the PathInput sample does is getting the next position on a path and placing the object there - in that many small steps, that it looks like the object is animating over the path when you keep holding the arrow keys. This is done by calling "move.tween.fullPosition = ...". If the distance between the steps is too big, it looks like the object is teleporting from one position to another along the path.

    If you are using a linear easetype, wouldn't starting the tween and pausing it after a fixed amount of time be an alternative solution as well? You would only need to set the pause interval to roughly the amount of seconds / distance you would like your object to travel. I hope this helps.
     
    ChooChooBuckaroo likes this.
  25. ChooChooBuckaroo

    ChooChooBuckaroo

    Joined:
    Oct 17, 2018
    Posts:
    8
    Thank you for responding!

    I was actually messing around with the splineMove code and realized that, as you suggested, pausing after a certain amount of time would be a viable option. I appreciate your time.

    Edit:

    I'm having trouble determining where to implement the timer for the pause. Would it be within StartMove() from splineMove.cs? Or within CreateTween? Or somewhere else?
     
    Last edited: Dec 20, 2018
  26. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    @richdunne You wouldn't modify the scripts of SWS directly. Just call the public methods provided from your own, separate script: Scripting Reference

    What you are looking for are the Pause() and Resume() methods. In your script, you can handle player input on your own and then interact with the movement script accordingly.
     
    ChooChooBuckaroo likes this.
  27. ChooChooBuckaroo

    ChooChooBuckaroo

    Joined:
    Oct 17, 2018
    Posts:
    8
    @Baroni

    Thanks so much, your guidance has allowed me to get everything working as intended! My final question: Because I'm stopping/pausing the spline short of the final waypoint, is there any way to invoke the easing animation as its stopping/pausing? Currently, the object stops abruptly.
     
  28. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    @richdunne Unfotunately the ease type you can specify in the inspector is applied on the whole path, not per segment or somewhen manually. There's no built-in method for "eased" speed changes, but you could write a coroutine that calls splineMove.ChangeSpeed(new value) over time, or even use DOTween to call that method over time using an easing tween.
     
    ChooChooBuckaroo likes this.
  29. DevilDarkSlayer

    DevilDarkSlayer

    Joined:
    Oct 11, 2017
    Posts:
    6
    Hello everyone,
    i'm sorry if this can be a stupid question but i have to do :D

    I have a 2d game and i move the player with SWS. The player is a swordsman. with left and right i move it without problems :)

    But: if i want to usa and attack animation, can i apply the root motion? if i do, of course my model move but quickly returns to my path point. I want to "tell" to SWS the movement done in the animation. Is it possible?

    Thank you very much
     
  30. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Hi @DevilDarkSlayer,

    let's see if I understand your question correctly...

    Currently, the OnAnimatorMove method in the MoveAnimator script takes the movement speed and direction and applies that to the Animator. With this input, the animator decides which animations to play. I guess what you would like to do is the opposite, take the animation and apply it on the movement tween? I am not aware of any public Unity methods allowing to access the root motion data on running animations, but if you find something, please let me know.
     
  31. DevilDarkSlayer

    DevilDarkSlayer

    Joined:
    Oct 11, 2017
    Posts:
    6
    Yes, is what i want to do.
    Imagine that: there is an attack animation which move the player forward.
    With the SWS i have to move artificially the tween during the animation. My question was: do the tween can "follow" the animation?
     
  32. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    @DevilDarkSlayer As I said, currently it works the other way around - the movement script sets the animation. If you could access root motion data, you could also set the movement speed.
     
  33. GeorgeCH

    GeorgeCH

    Joined:
    Oct 5, 2016
    Posts:
    222
    Just bough the asset for a shmup I'm working on. Works great, but how can I disable orientToPath? I can't find it exposed anywhere, in Inspector or in code.
     
  34. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Hi @GeorgeCH,

    orientToPath has been replaced by the path type setting. For the object to not orient to the path, you would set "path type" to "ignore".
     
    GeorgeCH likes this.
  35. vsgt

    vsgt

    Joined:
    Jan 28, 2019
    Posts:
    2
    Hello

    I'm making simple point&click adventure and I need help to figure out is this asset appropriate to me.

    So my task is to define a path, kinda "rail" on which the player's character moves.

    My task is: player clicks somewhere on the level, clicked point projects on the rail and the character moves along the rail to this projected point with predefined speed.

    - Can SWS project some given point to the path?
    - Can SWS execute the move to this point? In most cases, the point will lie somewhere between SWS waypoints?
    - Does SWS have a method like splineMove.GoToWaypoint but instead of instant teleport it executes moving to this point?
    - Can I add new waypoint between waypoints in the runtime?
     
    Last edited: Jan 29, 2019
  36. GeorgeCH

    GeorgeCH

    Joined:
    Oct 5, 2016
    Posts:
    222
    Thank you! Worked perfectly, though it may be helpful to update the documentation.
     
    Baroni likes this.
  37. Andreas12345

    Andreas12345

    Joined:
    Oct 17, 2013
    Posts:
    526
    i ve tried a navMesh mov, but why is the object not moving further?



    Its stops after the seconds waypoint and return!?
     
  38. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Sorry for the late response, I was out of office for a few days this week.

    @ValSgt
    It depends on which movement script you are using. The splineMove script uses DOTween i.e. fixed tweens created at runtime, like an animation. As such, by design, it is not suited for runtime path changes and dynamic movement which requires "changing path detection" in any way.
    On the other hand, our navMove script uses Unity's pathfinding, which is specificly designed for changing environments at runtime. If you are just in need of a point&click behavior though, you wouldn't need a waypoint system for that. I hope this answers the first two questions.
    Usually you wouldn't use GoToWaypoint at all. Instead, as changing waypoint position requires restarting the path due to the limitations mentioned above, you would just call movementScript.StartMove() again. The object then moves or teleports to the first waypoint of the path, depending on whether "moveToPath" is set to true or not.
    Yes, but changing paths requires restarting the movement script, as mentioned above. In both cases splineMove or navMove, you could assign the nearest waypoint and let the object start moving from its current position.

    @Andreas12345
    Thanks for the video. The stopping distance on your NavMesh Agent is set to 0. As such, the agent will have to match the destination point exactly, which is not likely to happen. Set it to an acceptable range instead, e.g. 0.5 or 1 units. Here is the official documentation.
     
  39. GeorgeCH

    GeorgeCH

    Joined:
    Oct 5, 2016
    Posts:
    222
    @Baroni

    Is it possible to use SWS to make objects remain at their starting point? It seems that even if I deselect the "Move to start" option, objects following a path will still begin with Waypoint 0 as the starting point.

    What I'm looking for is the following use case:

    1. I have a path (say, (0,0), (1, 0), (1,1), (1,2).
    2. Object 1 is instantiated at 0,0 and follows the aforementioned path
    3. Object 2 is instantiated at -1,0, so when its follows the path, its actual coordinates in world space would be (-1,0), (0,0), (0, 1), (0, 2)

    Essentially, I'm looking to use the waypoints as a form of offset from the starting position, without the object itself magically zipping (or moving to) the starting position.

    I'm actually working on a top-down shooter and am planning to use SWS for create and handle groups of enemies getting into a specific formation, by following the same path but from different starting points.
     
  40. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    @GeorgeCH You're looking for local tweens - but not local to the path, but local to the object itself. I have a development version including an improvement for that. Could you please send me an email (support address) with your invoice no. so I can send you the modified files?
     
  41. GeorgeCH

    GeorgeCH

    Joined:
    Oct 5, 2016
    Posts:
    222
    @Baroni

    Upon reflection, I ended up taking a different approach that does not require local tweens.

    Just one question - is there any downside, in terms of performance or otherwise, to having multiple Waypoint Managers per scene? I'm working on creating a set of Galaga-style enemy groupings, and I use SWS to manage their entrance onto screen and arrival to the final position. Just to keep things compartmentalized, I ended up creating a separate Waypoint Manager for each pattern, with a separate path manager for each path within that pattern, with the enemy assigned as a child of the path to avoid subsequent scaling issues.
     
  42. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Paths get added to the WaypointManager on initialization. With multiple WaypointManagers in the scene, I guess there could be issues with referencing the correct WaypointManager that holds your path, in case you are trying to assign paths dynamically via code. I don't think that it would be an issue performance-wise. It doesn't need to be a WaypointManager though, you could just use an empty game object as a parent too.
     
  43. Greg-Bassett

    Greg-Bassett

    Joined:
    Jul 28, 2009
    Posts:
    628
    Hi,

    Your website no longer seems to be available? I am trying to find the scripting reference.

    www.rebound-games.com/docs/sws


    I am using SWS to create a bezier path to plot out a path around a race track which I can do no problem.

    I will then use the waypoints from this bezier path for my AI cars to follow. However my AI cars require many more waypoints than are created for the bezier path, therefore I want to write a script to get the handle positions along the path from which I can create more waypoint gameobjects for my AI cars to use.

    Hope that makes sense, so in a nutshell I just need to be able to retrieve the handle positions from a bezier path.

    How can I do that?


    Thanks in advance for your help!
     
  44. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Hi @Greg-Bassett,

    our website and scripting reference is up again.

    Unlike regular PathManagers, BezierPathManagers have a pathPoints array (populated at runtime) which includes all points on the path (yellow path dots). Also, there is the bPoints list which saves waypoints and control points for the bezier path. I think this is what you are looking for.
     
  45. Greg-Bassett

    Greg-Bassett

    Joined:
    Jul 28, 2009
    Posts:
    628
    ok, perfect!

    How do I read the bPoints list? do you have an API for SWS?
     
  46. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
  47. Greg-Bassett

    Greg-Bassett

    Joined:
    Jul 28, 2009
    Posts:
    628
  48. Greg-Bassett

    Greg-Bassett

    Joined:
    Jul 28, 2009
    Posts:
    628
    I can confirm the pathPoints array is exactly what I need! Brilliant! Thanks!
     
    Baroni likes this.
  49. paugoert

    paugoert

    Joined:
    Feb 17, 2019
    Posts:
    3
    Hi,

    I make a simple "game". it has 10 steps (waypoints), user inputs a number between 1 to 3, an object (cube) keep move the chosen number of step (waypoint) until to the end. I put the following code and the cube move immediately (when program run, the cube is already there).

    I know the code is not doing what i want. i am just finding a method to move the cube smoothly from waypoint 0 to waypoint 2 and then stop there.

    Can u give me some idea ?

    void Start()
    {
    move = GetComponent<splineMove>();
    move.StartMove();
    move.Pause();
    }

    void Update()
    {
    move.GoToWaypoint(2);
    }
     
  50. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,262
    Hi @paugoert,

    your code doesn't work because Update is called roughly 40 times per second, and you are telling the object to go to waypoint 2, 40 times per second.

    To approach this, first you would write your own script that saves the user's input in a variable.

    Next, write a method in that new script that calls Pause() on the movement script. Add an if-check to only call Resume() on the movement script when the user's input is greater than 0. After that, substract 1 from the user input variable.

    When your user presses a number, let it call the above method as well.

    Finally, add an event in the movement script inspector to each waypoint calling this new method. So the idea is that your object pauses on each waypoint, but resumes as long as the user input variable is greater than 0, until it comes to a hold.