Search Unity

Simple Waypoint System (SWS) - Move objects along paths

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

  1. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,331
    Hi Baroni,

    I'm trying to move a simple sphere on a closedLoop. I would like the ball to start at waypoint 0. In the video, I used the included example that comes with SWS to test. In this test, instead of using Ethan the character, I used a sphere. Walker( Path3-1) is set at Position (0,0,0) Rotation (0,0,0). Path3-1(Closed Loop) also is set to the same zero position/rotation. Instead of the expected behaviour of simply moving the sphere, it first does a small loop before doing the right thing. Here is the video.

    https://dl.dropboxusercontent.com/u/48378123/SWS-ClosedLoopProblem.mp4

    Edit: found the solution. In the splineMove script, I have to uncheck the MoveToPath bool.
     
  2. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,331
    Bug Report: Bezier path.
    When I manually move the individual waypoints gameObjects instead of SWS node gizmo , it doesn't update the bezier path. I have to click on the parent pathManager object in order to update the drawn path.
     
  3. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    Hi rocki,
    for bezier paths, updating the path is a heavy task and you wouldn't want to do this at every frame in the editor, because it would cause Unity to lag. That's why this is done only when necessary and only if the BezierPathManager is actually selected. If you want to update the path at runtime, BezierPathManager has a method for it called CalculatePath.
     
  4. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,331
    I am using Curvy Spline and it doesn't have this problem at all.
    Perhaps you might want to at least update the path onMouseUp() so that after the user drags the node the path is updated. This will make for a much more user friendly experience, at the moment, not having the path updated after dragging the node causes much confusion to the user and really is a bug.
     
  5. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    Curvy is a different package and handles things differently. Updating the path on every mouse click would cause the same issues if there are more than a few bezier paths in the scene. I wouldn't call it a bug, because it is designed to work like that. The gizmo handles are meant to update the path, and there is also full source code provided if you would like to customize something after all.
     
  6. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,331
    It could be designed like that but the user experience is not very friendly, once a person moves the node using the inspector, then it's very confusing why the path or the node is not updating.
     
  7. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    @rocki
    I absolutely get what you are saying, but sometimes I have to make trade offs between usability and performance.
     
  8. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,331
    Cool, from your statement, I am assuming that you did try make it work by not updating every frame but using the mouseUp event but the performance was still too bad ? Is this correct?
     
  9. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    @rocki Yes, updating every frame or on every mouseUp event didn't make much difference, especially if there are more than 10 paths with many waypoints in the scene. Performance depends on your path setup (and amount) of course, but I'd like it to behave efficient even with a few hundred paths in the scene.
     
  10. paramitaUni

    paramitaUni

    Joined:
    Oct 11, 2014
    Posts:
    7
    I bought last week. Great asset!!

    But, I have a big issue. For testing I created a simple path, and put character into scene. The character CAN move with the path. However, his facing direction can't change. I don't know why... Did I miss something in my path configuration?
     
  11. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    @paramitaUni
    Thanks for your purchase! You mean that you've enabled orientToPath on your movement script, but your model is facing the wrong direction, correct?

    This probably means that your model has a different rotation than the movement script is expecting. To fix that, you can either:
    - go back in your modelling application and rotate the model there, or
    - create a new gameobject in Unity, attach the movement script to this new gameobject and make your character a child of it. The movement script will now move the parent instead of your model directly, so you can now rotate the child to the desired rotation.
     
  12. paramitaUni

    paramitaUni

    Joined:
    Oct 11, 2014
    Posts:
    7
    Hello Baroni, thanks so much for your detailed help. I just fixed this issue by creating new game object and make character as child.

    Thanks a lot!
     
    Baroni likes this.
  13. K1kk0z90_Unity

    K1kk0z90_Unity

    Joined:
    Jun 2, 2013
    Posts:
    84
    Silly question, but I want to be sure before buying: does it work with Free version of Unity?
    Thank you in advance for your answer! :)
     
  14. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    Don't worry; yes it does!
     
    K1kk0z90_Unity likes this.
  15. K1kk0z90_Unity

    K1kk0z90_Unity

    Joined:
    Jun 2, 2013
    Posts:
    84
    Thank you very much for your quick reply! :)
     
  16. aigam

    aigam

    Joined:
    Dec 31, 2005
    Posts:
    170
    Hi!
    i really like your solution, is almost perfect.
    Do you think there is any way to implement navmesh with splines, or with beziers? Or at least to use the bezier point to create a curved path?
     
  17. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    Hi aigam,
    Unity's NavMesh system uses pathfinding, you won't be able to create curved paths with it due to its nature. That's just not what a pathfinding system is meant for. You can create any path shape with bezier paths (select bezier path in the Waypoint Manager), or did I misunderstood your second question?
     
  18. aigam

    aigam

    Joined:
    Dec 31, 2005
    Posts:
    170
    Hi, yes, I will modify navMove to use the points on the bezier path instead of the wayponts, to see if this creates a curved movement.

    Thks
     
  19. mehzzz

    mehzzz

    Joined:
    Nov 5, 2014
    Posts:
    1
    I have a question. I have a simple enemy doing a patrol. It has a trigger set up so that when a player comes with in range, it just just follows them until the player gets to a safe point. How do I disable Simple Waypoint System so that my enemy stops following the path? I realize this might be a very base question, but I've been reading through this thread and the docs and currently can not find a solution. I thought of just disabling the scripts on the objects, but GetComponent doesn't seem to be an option.

    Thank You.
     
  20. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
  21. serseralci

    serseralci

    Joined:
    Nov 24, 2012
    Posts:
    5
    Hi Baroni,

    I bought your tool recently and started using it right away without any problems. Good job :)

    My question will be about rotating a GameObject through the path.

    Basically what I would like to do is, set a path to a a game object and make it both move and rotate throughout the path. Position values are tweened perfectly but Rotation did not tween. Will the library support that functionality any time soon?

    Cheers
     
  22. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    Hey serseralci, thanks for using SWS. Did you enable the "orient to path" setting on the movement component?
     
  23. Marceta

    Marceta

    Joined:
    Aug 5, 2013
    Posts:
    176
    Hi Baroni,

    [Problem solved] I just should use my brain liitle bit more, sorry for interrupting. Didn't see tween.GetPointOnPath.

    I would appreciate you help, if you could take a look at my problem. Im creating Zuma Deluxe game clone and i found your plugin very useful for it. Right now i have created spawn system for game ball's and it's working perfect with your plugin. Basically i spawn new ball every 0.4 sec store them to List and set path to them.
    Im now working on shooting new ball which would add them self to "ball's chain" at collided position. Any idea how i could control that? How i could move(increment/decrement) current position of balls, because for example ball can be placed somewhere bettwen 2 other balls.

    Original gameplay:
     
    Last edited: Nov 28, 2014
  24. serseralci

    serseralci

    Joined:
    Nov 24, 2012
    Posts:
    5
    Hi Baroni,

    I tried that solution before I read your reply but it seemed to me that the object always faces where it is moving to, but I did not changed the rotation AND set that option to true at the same time back then. I will try it tonight and update this post.
     
  25. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    @Marceta
    Hi there, glad you solved it. Let me know if you run into any problems.

    @serseralci
    Wasn't that what you were up to by stating "rotate throughout the path"? OrientToPath will indeed let the object follow the paths orientation. If you only want to rotate your object manually, say 360° in a loop, just disable OrientToPath and attach your custom rotation script to it.
     
  26. vik111

    vik111

    Joined:
    Feb 19, 2013
    Posts:
    13
    Hello Friend,

    It was nice plugin.

    I have got stuck at one point please help me asap if you have any idea ..

    My Question is : Can we Assign Another path to Object at run time ?

    Like we have 2 path if i press "A" the Path A should followed by object and if i press "B" Path B should Followed.

    Please Help me how it can be possible to do this...Thanks.
     
  27. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    Hi vik, have a look at the scene "Example_5_Runtime" and the RuntimeDemo script. Example 2 uses a button to switch paths of an object. Scripting reference is here. Pseudo code:

    Code (csharp):
    1. <your movement script> move = <your gameobject>.GetComponent<your movement script>();
    2. move.SetPath(WaypointManager.Paths["your path name"]);
     
    vik111 likes this.
  28. serseralci

    serseralci

    Joined:
    Nov 24, 2012
    Posts:
    5
    I see. Then I will need to tween rotation with another script. Thanks for the reply Baroni.
     
  29. phidias168

    phidias168

    Joined:
    Sep 6, 2012
    Posts:
    8
    I using PlayMaker(ver 1.7.7.f6). And bought SWS,in example_PlayMaker 's setwaypoint of path. When I play, the waypoint1 had be taken place by waypoint(new). But the path does not recreat new path. The walker still walked along the old path. Why it is? Does the walker should be walk along the new path which waypoint 1 is replace by new position of waypont1(new). Please check that and replay to me. Thanks.
     
  30. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    A new tween gets created on the current path, each time your walker starts moving on it. Tweens do not update their positions automatically when waypoints changes (unlike navMove and pathfinding), so you have to start on them again to take effect.
     
  31. phidias168

    phidias168

    Joined:
    Sep 6, 2012
    Posts:
    8
    Thanks for Baroni gave me advice. I used SWS_srart_moment after replace waypoint(new) position. Then the walker can walk along the new path.
     
    Baroni likes this.
  32. Unity_BO

    Unity_BO

    Joined:
    Feb 15, 2014
    Posts:
    5
    This plugin looks awesome! Exactly what i need. But before i buy it, one question: is it possible to move along a curved spline or bezier curve with constant speed?

    Regards
     
  33. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    Hey BO, thanks for your interest. Yes, it is.
     
  34. vik111

    vik111

    Joined:
    Feb 19, 2013
    Posts:
    13
    Hi vik, have a look at the scene "Example_5_Runtime" and the RuntimeDemo script. Example 2 uses a button to switch paths of an object. Scripting reference is here. Pseudo code:

    Code (csharp):

    1. <your movement script> move = <your gameobject>.GetComponent<your movement script>();
    2. move.SetPath(WaypointManager.Paths["your path name"]);

    Thanks a lot Baroni For your very important Reply.. but still i am confused because through this way the player always start a movement from start and i want it like there are the same path then player should start from same position just like Subway surf game. Please help me with this.
    Thanks.
     
  35. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    Remembering the latest position on the old path and then switching to the same position on the new path is a bit more difficult. First I recommend using the minimalMove movement script, if that's possible in your setup. You can access the current path progress via tween.fullElapsed (time value) and fast-forward it to this position after switching to the new path. Note that this only works if both paths are identical, otherwise the position on the old path wouldn't match with the new path.

    Code (csharp):
    1. minimalMove move = <your gameObject>.GetComponent<minimalMove>();
    2. float timeElapsed = move.tween.fullElapsed; //store current progress
    3. move.SetPath(WaypointManager.Paths["your new path"]);
    4. yield return new WaitForEndOfFrame(); //wait until the new tween is initialized
    5. move.tween.GoToAndPlay(timeElapsed); //fast-forward to the old position

    Another approach to this would be to only have one path in the scene and repositioning the path with the player, instead of switching paths. Especially in an endless runner game, that would make more sense.
     
  36. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    541
    I have a question regards suitability of SWS for my needs.

    I am currently using PolyNav to find paths for my AI entities to follow, but it has some limitations. One of the major issues I have with all these AI path-finding systems is they tend to be very focussed on using the in-engine AI agents. In my case, I am just after a path-finding system. I use my own AI to control ships to fly around waypoints (the only have rotate and thrust actions and use free-floating).

    Given PolyNav is basically creating waypoint path finding from collision geometry, I should be able to just use a waypoint system and mark points around my targets myself. I'd then need to be able to call on SWS to create a valid path from a ship to its intended target as a list of nodes. Is this possible, and what is performance like on mobile?
     
  37. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    @Shifty Geezer
    Hey, you can certainly create paths in SWS at runtime out of your waypoint positions and let your objects follow them. Please note that there is no pathfinding system in Simple Waypoint System, which could "create a valid path" for you. Movement in SWS happens on a fixed path from waypoint to waypoint, just like animations. There's also a movement script utilizing Unity's NavMesh system for real pathfinding included, but again, it also needs a pre-defined waypoint array (target positions array) to move along.
     
  38. Skyfly

    Skyfly

    Joined:
    Jan 25, 2014
    Posts:
    102
    Can i just use SWS to manage my waypoints with playmaker at runtime (adding, changing, deleting waypoints) and e.g. look up the next waypoint and do the movement with my own methods (runtime tracking of enemies, collision detection)?
     
  39. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    Most of this would be up to you, as there are only PlayMaker actions for getting and setting a waypoint at the moment. Of course you can create and use your own movement scripts if you like to; there's full source code provided and the path is basically just an array of gameobjects.
     
  40. cybervaldez

    cybervaldez

    Joined:
    Aug 16, 2014
    Posts:
    87
    Hi! 2 Questions:
    1. Do you have a demo or manual/tutorial on how to use this in 2D?
    2. If i'm already using HotTween, is it possible to use that instead of iTween?
     
  41. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    Hi valdez,
    1. the first post has a webplayer with a 2d sample in the fourth scene, which is also included in the package.
    2. this package does not use iTween, only HOTween.
     
  42. cybervaldez

    cybervaldez

    Joined:
    Aug 16, 2014
    Posts:
    87
    Cool! Last question, will this ever be updated for DOTween?
     
  43. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    Yes, once DOTween has the path plugin and it is out of alpha/beta.
     
  44. hnmikechan

    hnmikechan

    Joined:
    Dec 22, 2013
    Posts:
    1
    Hello,

    Is there any way to set the path as a child of a moving object and have the path update its transform during runtime? I have multiple orbiting objects, with each of those having child orbiting objects, but the paths don't follow their parents.

    Thanks,
     
  45. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    Hi, yes there is. Make sure to check "Local" on the movement scripts following the path. The example scene "Example4_Advanced" has a sample with a rotating path (see the "Local" section).
     
  46. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    Watch out for a new, overhauled edition of Simple Waypoint System!
    With @Izitmee 's DOTween out of alpha and freely available on the Asset Store, the upcoming version will switch its internal tween library from HOTween to DOTween (HOTween²), resulting in even more performance benefits.

    Along other improvements, the next update also introduces:
    - "Inverse" checkbox on movement scripts for toggling the moving direction on a path
    - moving on partial parts on a paths: e.g. waypoint 2-5, thanks to DOTween's new GoToWaypoint method
    - UnityEvent callbacks per waypoint: easily set up your own script calls in the inspector (like the OnClick event for a UIButton)



    Soon™
     
    cybervaldez and tosiabunio like this.
  47. desyashasyi

    desyashasyi

    Joined:
    Nov 22, 2012
    Posts:
    73
    Hi Baroni,
    For example, My agent have three paths in a road cross section. If the agent want to change the path, how to achieve it? Thanks
     
  48. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    @desyashasyi
    Hi, <yourMovementComponent>.SetPath(WaypointManager.Paths["new path name"]) sets a new path and starts from its beginning. You can also call SetPath directly with the new PathManager object. Scripting Reference (for navMove)
     
  49. desyashasyi

    desyashasyi

    Joined:
    Nov 22, 2012
    Posts:
    73
    Hi Baroni,
    Thank you. I have others question. I am using Playmaker to control agent movement. How to get current index of waypoint? and How to assign path manager at runtime with method game object (that contain path manager). Thanks.
     
  50. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,307
    If you're a PlayMaker user please import the additional PlayMaker package that's included in SWS. It comes with several actions for movement & path scripts and also a separate demo scene that showcases all of them. To switch a path you can use the "SWS_Set Path" action, getting the current waypoint (currentWaypoint) can be achieved with PlayMaker's GetProperty action.
     
unityunity