Search Unity

Simple Waypoint System (SWS) - Move objects along paths

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

  1. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    Hey @coverpage, I'm not quite sure what you mean by "solution for jump animation". Do you want to trigger the jump animation manually e.g. by pressing a key, or should it play automatically based on the path height difference? If it's the latter, could you elaborate what exactly you're having issues with? You could either place waypoints at the "jump start" and let the animation play via an event, or have a script running all the time which checks for the current position and the position further ahead (tween.GetPathPoint(tween.ElapsedPercentage + 0.05f) would be 5% ahead), then get the vertical difference of that.
     
  2. coverpage

    coverpage

    Joined:
    Mar 3, 2016
    Posts:
    385

    It is the latter. And yes I want to use the script running all the time as the path in generated at runtime procedurally. I think I did not look ahead far enough. And I actually checked something like, waypoint[i+1].transform.position.y - waypoint.transform.position.y. Either that or the Path[0] array in the SplineMove.cs in a similar fashion.

    I will try that tween command. Thanks. Also you might want to consider including this in the moveanimator helper script as i think it does add value to the solution.
     
  3. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    @coverpage checking waypoint[i+1] depends on the distance between your waypoints, while tween.GetPathPoint(...) does not. I'm still wondering what you are doing though and see this as a specific need of yours, so I don't think that adding this as default would improve the animator - or even break it for someone not looking for jumps.
     
  4. coverpage

    coverpage

    Joined:
    Mar 3, 2016
    Posts:
    385
    I'm using it for pathplanning where the pathplanning algorithm give a me a bunch of points and I smooth it out using SWS. SWS gives me a pretty neat visualization of the path as well. I need to take care of the jumping animation now. Since moveanimator is for humanoid animation, it might be more generic if it can handle vertical tweens, but I'm not pushing for it.

    I think SWS is a well designed very intuitive system for waypoints. Thanks for the support.
     
    Baroni likes this.
  5. SpencerPDX

    SpencerPDX

    Joined:
    Jan 3, 2012
    Posts:
    165
    Hello! I've used SWS for moving ground vehicles and people on foot, and find it to be a great system and so easy to use. Now I'm attempting to make an airplane fly through a scene. I'd like for the plane to lean into its turns, and am not quite sure how best to do this. I've not played with the bezier path type - is that the way to go? If so, it seems like I can't convert a path to bezier after the fact - is that the case, and I have to recreate it from scratch? I also see in the instructions there's a Waypoint Rotation option, but as soon as I activate it I see that each waypoint will have to be manually rotated - the plane no longer orients to the path. That seems like a ton of work compared to systems I think I've seen (probably in 3ds Max), where the lean either occurs automatically, or can added as a tweak to the animation of the object following the path.

    Any help would be greatly appreciated!
     
  6. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    Hi @SpencerPDX, it is correct that you cannot convert an existing path from/to bezier paths (without code). The Waypoint Rotation feature would be the way to go for airplane turns, as it was specifically designed for that. It doesn't matter which path type you are going to use for that though.

    Press the 'Rotate Waypoints to Path' button on the PathManager, then go from there.
     
  7. SpencerPDX

    SpencerPDX

    Joined:
    Jan 3, 2012
    Posts:
    165
    Hi @Baroni, that seems to work! Thanks for the lighting fast reply.
     
  8. GPSTVR

    GPSTVR

    Joined:
    Nov 4, 2016
    Posts:
    5
    Hiya,
    I've got a small issue.
    I'e created a path and a object that needs to follow the path. However, this specific object always set itself 180 turned when following the path...Have you come across this issue before?
     
  9. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    Hi @GPSTVR, your original object rotation is oriented to a different orientation than Unity expects. You have two options for solving this:
    - go back to your modelling application and rotate the object there, then export it again, or
    - create an empty game object and attach the movement script to that. Then make your object a child of it and rotate its transform to the correct orientation.
     
  10. GPSTVR

    GPSTVR

    Joined:
    Nov 4, 2016
    Posts:
    5
    omg, that did the trick. Of all the things that I tried, that I didn't :( Stupid me! Thanks for the quick resonse!
     
  11. erich202

    erich202

    Joined:
    Sep 24, 2016
    Posts:
    38
    Hi all,

    My 2D sprite is disappearing when I play. I can't see any changes that would cause that in the renderer, shader, position, etc. Any ideas I can try out?

    Best,
    Eric
     
  12. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    Hi @EricMuyser, maybe the rotation flips when starting the tween? Did you set the path mode on the movement script to 2D instead of 3D? Another alternative would be that your object has an animation attached to it that modifies its position or rotation.
     
  13. artysta

    artysta

    Joined:
    Nov 15, 2009
    Posts:
    124
    I have a situation thats been working for a long time but now has stopped working.
    I have a project that has 6 scenes in it. 2 of these scenes carry a SWS path, one is a normal game object, one has the camera following the path. There's only 1 path per scene.
    Everything works fine except when I repeat the scene a second time.
    The first time through all plays great, I can pause, resume, both work fine.
    But if I end the scene, or quit to the main menu, then using my menu system and play the 2 scenes over that have a SWS path, they are frozen, everything working, but the game object won't start.
    If tried many combinations of starting/resetting the path, but nothing works. Both through the GUI system or from C# script.
    What am I missing? I don't carry anything over from scene to scene except some simple scoring prefs. I don't need the game object to start where it left off, everything is reset.
    Any help? How can I play a scene more than once without quitting the app and have the path not frozen after the first play?
     
  14. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    @artysta It's difficult for me to know what causes this, because I haven't experienced that yet. Did you try the first SWS example scene in a new project? The first example scene has a GUI for switching scenes so you can simulate the level changes and repeat a scene. Please report back if this happens in the sample scenes (and a new project) as well. If it doesn't, we'll have to investigate your specific settings or project.
     
  15. artysta

    artysta

    Joined:
    Nov 15, 2009
    Posts:
    124
    Thanks I will try that, I haven't had the examples loaded in, I will re-import and check them out.
     
  16. artysta

    artysta

    Joined:
    Nov 15, 2009
    Posts:
    124

    I loaded a new project and imported SWS and the scene switching demo works fine. I will have to investigate why after months of working fine, that I cant replay a scene with a path in it more than once. I don't get any errors so its hard to deconstruct, the object just sits at waypoint 0 and animates. Thanks, I will see what I can see.
     
  17. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    @artysta If you can strip down the project and it still reproduces the issue, you can also send this minimal project version to our support email.
     
  18. artysta

    artysta

    Joined:
    Nov 15, 2009
    Posts:
    124
    I found the issue, in my change scene code there was some older code that I now deleted as its not needed.
    Before calling the load scene, I was destroying old game objects. This was destroying something
    in SWS that wasn't recreated when started back up during a re-load of the scene. Now that its gone, all is well.

    GameObject[]GameObjects=(FindObjectsOfType<GameObject>()asGameObject[]);
    for(inti=0;i<GameObjects.Length;i++)
    {Destroy(GameObjects);}
     
    Baroni likes this.
  19. IgorAherne

    IgorAherne

    Joined:
    May 15, 2013
    Posts:
    393
    hi @Baroni,

    How can I get the waypoint index if I know the tween.ElapsedPercentage() ?
    If not possible, are there any workarounds? I really need to make it (Normal, Bezier), I don't care about performance hit, - need the functionality just for the editor

    And also, knowing the index of waypoint, can I retreive tween.ElapsedPercentage from it? I am happy to use Invisible gameObject with spline move to navigate the path in the background.

    Thank you for help!
     
    Last edited: Feb 2, 2017
  20. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    You would need to use a game object running a tween for that too - there is no way to access something that has not been created. If you send the tween to the percentage value using tween.fullPosition (takes a time value in seconds), you can then get the currentPoint variable of the movement script directly.

    Similar like above, but using movementScript.GoToWaypoint and then getting data from the tween.
     
    IgorAherne likes this.
  21. baroquedub

    baroquedub

    Joined:
    Aug 27, 2015
    Posts:
    11
    Just imported SWS into my project and suddenly getting random Invalid AABB aabb UnityEditor.DockArea:OnGUI() errors appearing in the console. This occurs in the editor, while working on my project. Not at runtime.

    Is this a known bug? (Unity 5.4.3 on Windows7)

     
  22. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    This isn't really something I can reproduce, since it isn't related to SWS and can be caused by particles, Unity version, editor layouts or other things. Please see the threads below... it's a Unity bug and should be submitted via their bug reporter (if you have tried / or don't want to update to the latest Unity version).

    https://issuetracker.unity3d.com/is...esult-appear-in-console-while-running-a-scene
    https://issuetracker.unity3d.com/issues/particles-invalid-aabb-slash-infinite-errors-in-5-dot-3-1
    http://answers.unity3d.com/questions/1226084/unity-540f3-invalid-aabb-aabb-error-after-upgradin.html
    https://issuetracker.unity3d.com/is...en-using-font-which-has-line-spacing-set-to-0
     
  23. RicardoFig

    RicardoFig

    Joined:
    Jul 1, 2014
    Posts:
    2
    Hello

    I want to implement a wayfinding system with your library, how can I do to leave red dots after the moving object is moving to the destination and delete them after another position is selected?
     
  24. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    Hi @RicardoFig,

    SWS is not a pathfinding asset. You have the option between fixed paths (tweens) and paths Unity's navigation system. Both provide ways to visualize the path, for example by drawing dots on the waypoints, or the path corners (in case of a NavMesh path, have a look at Unity's official documentation for that).
     
  25. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    Hi @Baroni ,

    I'm having some really crazy connections between one path and another sometimes,
    For example look at the path between these two example paths in screenshots:
    Screen Shot 2017-02-20 at 4.28.39 PM.png Screen Shot 2017-02-20 at 4.29.19 PM.png

    Is there something I can do to minimize potential crazy paths ? I have a mecanim character
    running around on these paths, and I just really need a simple linear path from one connection
    to the other, but sometimes I get these crazy connections. Any ideas ?

    I have both PathManagers and Bezier Path Managers, could that be the issue when connecting from one type to the other?
     
    Last edited: Feb 21, 2017
  26. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    Hey @invadererik,

    thanks for the screenshots. The first image looks like DOTween could have issues with floating point precision in your (potentially) huge world, where it inserts another waypoint at the start and tries to move through that too. Other causes can be scaled transforms/paths.

    The second screenshot looks like the object started from that position (is moveToPath enabled?) but if it didn't, it could also relate to the previous issue as well. Connecting spline and bezier paths should not cause any issues.

    It would be great if you could pinpoint the issue to these two paths and send me a repro via email, so I can take a look at the scene boundaries and check whether that is indeed causing it.
     
  27. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    @Baroni oops, after much poking about, I ended up finding that it was actually the Rigidbody on my character. I just set it to Kinematic while its on the path for now. You would think the effect of that would have been lots more noticeable but, nope.

    Another small issue I noticed while trying to fix this one. If you have an object traveling on several paths, and you set an event on one of those paths, then when you add a new path using splineMove.SetPath( aPath ); this command does not clear the events from a previous path. I'm currently clearing the list and adding new events the size of the new path.

    In my opinion I think this should probably be default behavior for SetPath() ...
     
  28. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    This is by design. It is much easier to clear the events when switching paths, than taking existing events over to another path with potentially different amount of waypoints. Meaning that instead of forcing you to reinitialize all existing events again when switching paths (if you would ever need the other way around), I am forcing you to reset the events list - which you did successfully, so it worked ;)
     
  29. RediceZone

    RediceZone

    Joined:
    Oct 1, 2014
    Posts:
    2
    i want to start my moving path from the specific point from given set of path ! how it can be possible i'm facing some movement of object rotation and others. please help me !
    I want to start move along my waypoint path container but from the specific index of way point , i set on runtime the variable 'currentpoint' to my desired point where i wanted to start but its not working fine as it starts from 0 point !
    @Baroni please help me !
     
  30. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Hey,
    is there a way to have one and the same object move along a path forward until reaching a certain waypoint and move backward afterwards? Think of a parking car trying to get into a parking lot.
    Or can this be done using two paths and switching between them using the event system?
    I tried that last option but couldn't figure out how to make the object move backwards - but it has to be possible since the yoyo-tween exists.

    edit:
    seems to be possible using ease type unset and defining a custom anim ease type curve
    though I'd still like to know if there are other ways to achieve the same, thx
     
  31. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    @RediceZone currentPoint is an internal variable thus not documented for modifications. It returns the current waypoint index along a path, but you should not modify it. You should use the 'startPoint' variable instead.

    Hi @Marco-Sperling, the Reverse method has been added to movement scripts to allow changing direction mid-path or on waypoints. I guess this is not what you want though based on your 'parking car' example, since you would want to only change the rotation, not direction? The easiest way would be for you to either use the 'waypoint rotation' feature of the latest version for full custom control over rotations, or have the actual car object as a child to the movement script and modify the child rotation at waypoints (which is then independent from the parent rotation).
     
  32. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    @Baroni
    Correct, the rotation of the object needs to change. The translational part would still follow the waypoint order:
    0-1-2 (object looks like moving forward due to its rotation)
    2-3-4 (object looks like moving backward due to its rotation)

    I thought about wiring up two paths since I doubt that I can control the rotation in a way that doesn't look odd (at a certain waypoint the object needs to flip 180 degree if doing it that way).
    One for the forward movement and one for the backward movement. And relying on the event system to swap them out.
    I need to see how far I get with this approach.

    edit:
    WaypointRotation looked like the right thing according to the example scene. But it created awkward rotational movement - on the first few waypoints it worked okay.
    After these the rotation more or less snapped to match the path direction instead of tweening/lerping into place.
    I tried increasing the path detail hoping to get smoother rotation - to no avail.

    By utilizing two paths I almost had what I wanted were it not for the first frame of the second path that the car snapped to the other side of if before starting at the correct end.

    I guess I'll do this stuff in Maya now and parent my car object to some bones.
     
    Last edited: Feb 27, 2017
  33. Wambhse

    Wambhse

    Joined:
    Aug 11, 2015
    Posts:
    13
    Hi I saw that you said you can let an object start at a percentage value on the path.... I was looking over the Documentation and I couldn't figure out how to do this. So how does one go about doing this through script? thanks.

    Oh, Also is there a way to have the ease type to happen at each way point and not just the beginning and end of the path? if not, this should really be added in.
     
    Last edited: Feb 28, 2017
  34. dearamy

    dearamy

    Joined:
    Mar 17, 2015
    Posts:
    68
    Will SWS support nonlinear path?
     
  35. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    @Marco-Sperling sorry, I don't get notifications if you edit your post. If you still have a scene that shows how you are having issues with setting this up with SWS, please send it over to the support email so I can take a look. The waypoint rotation feature is in experimental stage, although it definitely should be able to handle that.

    Hi @Wambhse, you can access the tween of a movement script and use the "low level API" of DOTween to do that, by using tween.fullPosition or tween.ElapsedPercentage. Having a different ease type per waypoint segment is not possible due to the way paths are being built - it's one or the other, but not both unfortunately.

    @dearamy what do you mean by 'nonlinear'? Curved and bezier paths have been supported for years now. Also there are several ease types or custom easing available for the path.
     
  36. dearamy

    dearamy

    Joined:
    Mar 17, 2015
    Posts:
    68

    I mean the path has branches, you know, like crossways, or some methods to combine several ways together. Thus you can create a real huge waypoint map.
     
  37. jkroeckel

    jkroeckel

    Joined:
    Feb 5, 2013
    Posts:
    1
  38. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    @dearamy you can use events or triggers to have moving objects switch mid-path to a target waypoint on a new path (startPoint variable) so that's kind of possible already, although it requires some setup for triggers. Also, combining several paths together (in a chain) is nothing more but calling StartPath on the following path.

    @jkroeckel Yes, that's outdated. Not only because it's 4 years old, but also since the underlying tweening engine changed. Please use the ChangeSpeed method on movements scripts, there is a sample in the runtime scene too.
     
  39. Justin-Wasilenko

    Justin-Wasilenko

    Joined:
    Mar 10, 2015
    Posts:
    104
    I just tried searching this lengthy thread but couldn't find an answer. When setting 'moveToPath = true;' is there a way to get rid of the snap that happens once the object reaches the first waypoint. In some cases it's really noticeable. Is there a way to smooth that out?

    The Editor draws nice new lines in white that would work perfect, but when playing the scene once I get to my yellow path the objects snap to the first waypoint.

    Is there a way to follow that new path that seems to be created?

    This is what I am doing to Instantiate and start following:

    Code (CSharp):
    1.         Transform repairTransport;
    2.         repairTransport = PoolManager.Pools[esStrings.levelPool].Spawn(RepairTransport, RepairSpawn[0].position, RepairSpawn[0].rotation);
    3.         splineMove pathTransport = repairTransport.gameObject.AddComponent<splineMove>();
    4.         pathTransport.pathContainer = pathArray[2];
    5.         pathTransport.moveToPath = true;
    6.         pathTransport.onStart = true;
    7.         pathTransport.speed = repairFleetSpeed;
     
  40. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    The way the 'moveToPath' functionality is built, is that movement to the path and moving on the path are two different things for more flexibility. This means that once the path is actually being reached, the movement tween is being rebuild for the path itself. Since the 'moveToPath' tween cannot know what a path tween will look like before creating it (before reaching the first waypoint), having an absolute smooth transition is something difficult to achieve.

    You could consider moving your object closer to the direction of the first waypoint, or trying the 'waypoint rotation' feature which allows for custom rotations along the path (but also interpolates with moveToPath set to true). Getting a smoother transition for auto-rotation tweens is on the to-do list for a future update (no date yet).
     
  41. coldstar

    coldstar

    Joined:
    Sep 20, 2014
    Posts:
    13
    how could I repositon waypoints in the path to make the path change at runtime?
    It seems not working when I adjust the waypoint of the path in the Editor at Play Mode.
     
  42. dacoursey

    dacoursey

    Joined:
    Dec 17, 2016
    Posts:
    40
    Hoping to buy this. I'm building my path coordinates at runtime, can SWS use these to make a sprite follow the path?

    Thanks!
     
  43. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    Hi @coldstar, changes to paths with a moving object on them only change on the next movement iteration, meaning that you'll have to stop-start your movement script again. If you want to make adjustments in the middle of a path, you can have your object start at a specific waypoint again (rather than at the beginning).

    @dacoursey paths can be created at runtime, given a set of transforms acting as waypoints. If you would like to get into that right away (after purchasing), please have a look at example 7 in the Example7_Runtime demo scene.
     
  44. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    742
    Does the asset provide a way to calculate cycles and non closed cycles from a graph of connected way points ?
     
  45. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    @SirChick what would be your desired output format for that?
     
  46. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    742
    A list, of a list of way points that form closed cycles, and a list, of a list of way points that do not have closed cycles.
     
  47. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    @SirChick not sure I understand, but there is no public method for calculating path cycles/loop points. That's something the underlying DOTween library is responsible for, which is also used for drawing the editor path lines, so this exists internally only.
     
  48. TheCelt

    TheCelt

    Joined:
    Feb 27, 2013
    Posts:
    742
    My aim was to use the way points to draw out a floor plan, thus a closed cycle represented a room on the floor plan. But no worries if it's not used for that purpose.
     
  49. dacoursey

    dacoursey

    Joined:
    Dec 17, 2016
    Posts:
    40
    Hi Baroni, I bought a license and I'm poking around now. I looked at Example7 like you suggested but that's slightly off.

    I'm already drawing a bunch of lines at runtime. What I want SWS for is to plop a sprite on one of them and have it follow the pre-existing path. Right now my lines are Vector2[], but I can convert to Vector3[] .

    Is there a better example of what I'm trying to do?

    Thanks for your help

    David
     
  50. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,265
    Hey @dacoursey, I guess a combination of example 1 (walker and path instantiation) and example 7 (runtime path creation) in the same example scene is what you are looking for? You first have to create your path based on your Vector3 points (like example 7), then instantiate/access your sprite with the movement script and assign the newly created path before calling StartMove on it.

    There is no way to let a movement script move on a given set of points without creating a PathManager component, so that's where you would want to start first.