Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Simple Waypoint System (SWS) - Move objects along paths

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

  1. jtw123

    jtw123

    Joined:
    Aug 13, 2020
    Posts:
    2
    Hello Flobuk

    Hope you are well. I am making a 2d Shoot em up game and I am wondering if this asset would help me solve my problem. Under my current system I am unable to get the enemy to rotate and have proper distance from each other. In the photo below, the enemies stack one on top of another and do not rotate. Would your asset allow a collection of 2d sprites to follow a path, with proper rotation and not one on top of another?


    Thank you for your assistance and have a great day.
     

    Attached Files:

  2. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    Hi @jtw123, thank you for your question. In Simple Waypoint System each object has its own movement script, but can share the same path. So each object can have individual settings for that path. Regarding rotation, your objects can have none, a 3D, 2D, 2D top-down or completely custom rotation. And for the distance - you could either place multiple waypoints on that path and assign each object to its own waypoint, or do it more manually and set a starting percentage (from 0-100%) for each of them.

    What you've asked is basically built-in and the most common use case (rotation and start point) for this asset. Hope this helps.
     
  3. jtw123

    jtw123

    Joined:
    Aug 13, 2020
    Posts:
    2
    Alright will give the asset a try, thanks for your help.
     
  4. Smashmaster01

    Smashmaster01

    Joined:
    Sep 8, 2017
    Posts:
    6
    What´s the best way to implement a rigidbody with some slope/stairs detection? As far as I can tell the splineMove script must be attached to the parent of the rb. To check for obstacles along the path you then have to use the parent´s direction, right??
    I tried to combine it with a rb and it works..kind of. Y-positioning looks very clunky, especially when falling off a slope. Maybe a sphere raycast works best? It´s independent of the parent´s direction as well. Locking the Y position is very helpful, still the very first waypoint is gonna teleport the player to the waypoint´s y position.
     
    Last edited: Sep 2, 2023
  5. Smashmaster01

    Smashmaster01

    Joined:
    Sep 8, 2017
    Posts:
    6
    Apologies for double posting, but after updating Unity to 2022.3.4f1 the waypointmanager is missing the StartPath button in the inspector. Any quick fix for this problem? Tried reimporting the asset and even started a new project without success.
     

    Attached Files:

  6. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    Hi @Smashmaster01, sorry for the delayed response due to the weekend. A rigidbody (with physics/gravity) cannot be used in combination with a movement script at the same time, as these would both race for control over the object. Physics would push the object down, while the movement script would try to constrain it to its path. For slope/stairs you would need to do this manually, e.g. using raycasts as you mentioned and then apply it to the object's bones. This should kept separate from rigidbody interactions. If you want the object to fall, you have to disable the movement script for the rigidbody to take over.

    You are in inspector debug mode, you have to leave that and go back to "Normal" (three little dots button):
    upload_2023-9-4_11-55-25.png
     
  7. Smashmaster01

    Smashmaster01

    Joined:
    Sep 8, 2017
    Posts:
    6
    Thanks for your quick response, that should do the trick. ;)
    Concerning the rigidbody problem: maybe you should create a simple sample scene, just for newbies like me. There are similar questions regarding rb in this thread too. If you say you can´t include every possible scenario that´s fine as well. I understand that both methods are fighting eachother, however my first idea was since everything (slopes/jumps/gravity) affects the y axis, you should be able to lock the y axis inside the path manager and ONLY update the y position through custom code.
     
  8. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    Thanks for the feedback and also regarding a simple example scene. I am planning a major update for the asset (since a long time actually) and will have to see how that fits in. The confusion could be around the "lock" behavior here, since that does not mean the y-position is not modified by the movement script: locking the y-axis means that its value is applied/forced by the tween to stay consistent during the whole tween duration, at the value where it was in the beginning. However you are free to apply your own code to that axis after the tween, e.g. in LateUpdate.
     
  9. Smashmaster01

    Smashmaster01

    Joined:
    Sep 8, 2017
    Posts:
    6
    Major update sounds very promising. Any info regarding an estimated release date? Maybe I should wait a couple of weeks.
    Looking forward to it!
     
  10. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    @Smashmaster01 It is still in the design phase with development not even started, sorry to crush your hopes :oops: I am thinking about providing alternatives to or replacing DOTween so that needs to be planned very wisely since that would potentially require an upgrade path for thousands of users.
     
  11. afifansyafaqi

    afifansyafaqi

    Joined:
    Nov 4, 2020
    Posts:
    2
    Hy, i would ask about why the last waypoint cant be delete(there is no a minus in last list)? i mean i just want to delete only the `Waypoint 5`, if its cant, how should i correctly do it?

    upload_2023-9-7_15-19-13.png
     
  12. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    @afifansyafaqi Good question, this has never been asked before :D There might have been a reason in the past, but I do not remember why, nor would it make much sense to prevent it in the UI. I'll add a note about this for the next update. For now, you could simply move "Waypoint 5" at the same position as "Waypoint 4" (right click copy Transform > paste Transform values) and then remove Waypoint 4.
     
  13. tyrot

    tyrot

    Joined:
    Aug 18, 2013
    Posts:
    36
    Hi there,

    I have a box and an Alembic imported character is walking on this box using SWS with no problem. However, when this box starts to rotate although waypoints are stuck on the box as they should be, the character does not follow this path.
    Is there a way to fix this?
     
  14. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    Hi @tyrot, did you take a look at the local tween sample (scene 04 Advanced)? Both the moving character and the path game object should be part of a parent object (i.e. the box) that has the rotation script attached to it. With this setup, on the movement script you can then enable local movement in the inspector. There is also a demonstration gif in this post.
     
  15. tyrot

    tyrot

    Joined:
    Aug 18, 2013
    Posts:
    36
    you sir .. a legend)))
     
  16. adscomics

    adscomics

    Joined:
    Nov 2, 2017
    Posts:
    13
    Is there a way to have paths move relative to a parent game object? Like, if I have an object move along a path, but that object's parent moves as well, right now the child moves along its path while ignoring the parent's movements, but I want the child's path to move with the parent. Is there a way for this to work? Is there something with DOTween that prevents this?

    EDIT: Okay I was able to figure it out. Child object has to be a child of the waypoint manager, with its LocalType set to "To Path", wit the waypoint manager being a child of the moving parent, if I understand correctly. That's how I got it to work for me at least. Lemme know if there's a better way to handle it though.

    EDIT 2: So actually I realized that the above solution only works if the path and waypoint manager share the exact same position in world space, which isn't optimal if I plan to have multiple paths with different starting positions. Other than having multiple Waypoint managers (if that's possible), is there a way to remedy this? I hope my explanation are making sense.
     
    Last edited: Oct 1, 2023
  17. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    Hi @adscomics, the WaypointManager does not need to be a child of anything - only the PathManager needs to be a child of the moving object. Please see my last reply above that also mentions "scene 04 Advanced" which contains a sample.
     
  18. AArtlone

    AArtlone

    Joined:
    Dec 3, 2018
    Posts:
    10
    Hi!

    I need some help.

    Imagine that I have a typical circular arena. This arena has an entrance corridor.

    I want my character to first walk through the corridor, and then start walking around the arena in a loop.

    Any advice on how to do this?

    Thanks in advance!
     
  19. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    Hi @AArtlone, thanks for posting. Have you had a chance to look at the samples already, especially the runtime sample scene which shows how to switch paths at any point in time? For example, you could have two paths - one for the entrance, and a separate one for the loop. Then using an event at the last waypoint of the "entrance path", or upon triggering a collider along the way, switch to the second path. Both "waypoint events" and "collider triggers" are demonstrated in the sample scenes as well. The path switching would be done via code, using <movement script>.SetPath(newPath).
     
  20. AArtlone

    AArtlone

    Joined:
    Dec 3, 2018
    Posts:
    10
    Thanks for your quick reply!
    Yeah, that helped. I am now able to switch from one path to another, all good!

    However, I am running into another, weird problem. I have attached screenshots to help me explain.

    Screenshot 1 - my path as it is set up before entering play mode.
    upload_2023-10-22_15-26-54.png


    Screenshot 2 - this is how it looks upon entering play mode (as expected because I set `closeLoop` to true). upload_2023-10-22_15-27-56.png



    Screenshot 3 - this is how it looks the moment my object reaches the initial way point after completing the first loop. For some reason the path changes, and a small loop gets introduced, which makes the movement super weird.

    upload_2023-10-22_15-28-15.png



    Screenshot 4

    upload_2023-10-22_15-28-24.png

    Any ideas on why this is happening? I have tried looking through examples, but could not find anything. I have tried rebuilding this path multiple times and tried different positions, but nothing helps, happens every time. Help :c
     

    Attached Files:

  21. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    Hi @AArtlone, I have tried to reproduce this in a sample scene but have not been able to. Once the movement script starts moving in a loop, the loop is not modified - you can even move waypoints but the path does not change (without stopping and restarting movement). I assume you are somehow restarting movement on each loop separately?

    The reason this small "side-loop" is happening is because of DOTween's internal path calculations and smoothing algorithm, SWS does not have any control over it. Maybe you could tell me your Unity version and send your repro case (scene exported as unitypackage, but runnable without any 3rd party assets) to my email? You can find my email on this page.
     
  22. AArtlone

    AArtlone

    Joined:
    Dec 3, 2018
    Posts:
    10
    Pffffffffffff, as I was typing my response I realized something stupid I left in my script. Before I implemented SWS I had some test code that would move my object up and down (just for testing). So I still had that code. It wouldn't move the ship, because SWS took over, but apparently, that is what caused that weird loop bug. As soon as I removed that code, the bug was fixed...

    Thanks a lot for your quick response and for your help!
     
    Baroni likes this.
  23. AArtlone

    AArtlone

    Joined:
    Dec 3, 2018
    Posts:
    10
    Hey, is it maybe possible to remove waypoints from the path at runtime? So for example, once the ship reaches waypoint 4, I want to remove the first 3 waypoints completely. Is this allowed?
     
  24. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    Waypoints are game objects which you can destroy at any point during runtime. Once waypoints have been deleted in the scene, update the corresponding PathManager by calling <Path Manager reference>.Create().

    However, there is the limitation that in order to have any effect on an already moving object, its movement needs to be restarted, using <movement script reference>.StartMove(). It can re-start from the new path beginning or a different waypoint by assigning the startPoint index before calling StartMove().
     
  25. Alexfightsevil

    Alexfightsevil

    Joined:
    Jun 24, 2019
    Posts:
    1
    Hi @Baroni! I am using the SWS for a 2D top down game but I am not understanding how to control or adjust the rotation during the path traversal. I read through the documentation but it was not clear to me how to adjust this. I want my sprite to navigate off of its top center point and travel forward from that rotation, so as it follows the line the top center point is rotated towards the direction it is traversing.

    I am linking to a google drive video that hopefully helps illustrate what I am not understanding.

    Thanks for helping!
     
  26. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    Hi @Rising_Phoenix, thanks for posting. You can create an empty game object and attach the movement script to that. Then, make your object a child of it and position it relatively exactly to where you want the pivot to be. Does that help? I hope I got your question right.
     
  27. _eternal

    _eternal

    Joined:
    Nov 25, 2014
    Posts:
    308
    Hey, I'm getting some CPU spikes when I try to start a tween using a bezier curve. It's coming from CatmullRomDecoder.FinalizePath().



    I know that this method is calling DOTween, but I think there's some sort of partnership between SWS and DOTween, right?

    Originally, I wanted to use DOTween for this, but I found that it only worked with basic curves, not beziers. Then I saw a comment on the DOTween documentation recommending Simple Waypoint System for dealing with complex curves. Right now I'm starting this tween with a splineMove component, but it looks like the performance hitch is somewhere in the DOTween code.

    Anyway, is there any way to smoothen this out?
     
  28. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    Hi @_eternal! It is correct that the path calculation, smoothing and tween animation is handled in DOTween internally. SWS provides the path creation tools and movement settings interface on top of this. Because of that, unfortunately I do not have any control over GC or CPU spikes within the path generation logic. However, if you are using a bezier curve, I would try tuning down the path detail (slider on the BezierPathManager inspector) for the whole path, so that the path generation is less performance heavy. Please let me know if this has any effect for you - thanks!
     
  29. _eternal

    _eternal

    Joined:
    Nov 25, 2014
    Posts:
    308
    Hey, thanks for the quick reply!

    Interesting, I hadn't looked into path detail. I ended up creating a bezier by code in DOTween like this: https://github.com/Demigiant/dotween/issues/75#issuecomment-468360897

    I haven't done any thorough testing, but this seems like it's faster in general - create the path in the editor, and then manually convert it to a Vector2[] and pass it to DOTween.

    It feels strange that this works - shouldn't path generation be equally slow regardless? - but it seems to work for now. I might circle back later to see if tweaking the path detail is actually more effective than what I'm doing.
     
    Baroni likes this.
  30. HonkaHonka

    HonkaHonka

    Joined:
    Feb 14, 2013
    Posts:
    6
    Hi there, I would like to use bezier curves to make my spaceships fly.
    The problem I have is, my ships do have something like an AIBrain - which controls their behavior, movement, attacking etc.
    So the ship flies happily on it's bezier curve with your script - a player enters the surrounding - the AIBrain takes over and shoots / follows player. Then the ship will not be on the bezier path any longer.
    What is the best way of "getting it back on track of the bezier curve" ?
    As I see it, the "move to path" only works at the beginning- or can I use "Initialize(nextWaypointInList)" to get it going again to the next WP?
     
  31. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    Hey @HonkaHonka!

    "Move To Path" can be modified at any time during runtime. After enabling it (moveToPath=true), you would call StartMove() as usual. For moving to a specific point, you can use the startPoint variable. However note that when used on bezier paths, this value is a bezier point index, not waypoint index. You can also preview it on the path when modifying it in the editor inspector, when not in runtime.

    Your code would look like this:
    Code (csharp):
    1. int oldPoint = (moveScript.pathContainer as BezierPathManager).GetPathPointIndex(moveScript.currentPoint); //optional save the waypoint where we were at
    2. //do your AIBrain logic
    3. //continue with path later
    4. moveScript.moveToPath = true;
    5. moveScript.startPoint = oldPoint; //or oldPoint + 1
    6. moveScript.StartMove();
     
  32. HonkaHonka

    HonkaHonka

    Joined:
    Feb 14, 2013
    Posts:
    6
    Thanks for your answer @Baroni I will try that out.
     
  33. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,513
    Hello, @Baroni, first off, thanks for this fantastic asset!

    My question may have been asked in this long thread already (I did a search for planes and banking), but I couldn't quite find the answer I was looking for.

    What I'd like to do is have the 3D plane object follow a path, where the plane's local up-vector is always oriented up towards the direction of the lookahead. I think this would simulate banking pretty well, aside from some anomolies where the lookahead up direction may be zero due to straight lines.

    I would imagine this would also be similar to if a path is on a banked race track, and a racecar would be oriented upward to match the race track banking.

    My current settings are:
    LocalType - None
    LookAhead - 0.15
    PathType Catmull Rom
    PathMode - Full3D
    LockPosition - None
    LockRotation - None
    Waypoint Rotation - All
    RotationTarget - None

    Thanks in advance for any help!

    EDIT:
    I see that DOTween has a DOPath() call with a SetLookAt() option that has some parameters to deal with roll. Does SWS have something similar?
     
    Last edited: Dec 27, 2023
  34. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    Hi @aer0ace, thanks for using it!

    Plane and/or race car orientation is a bit fuzzy to get right, caused by the tween not knowing which direction is "up" and not being able to "lean" into the next curve automatically. Having the PathMode set to Full3D might result in weird rotations on the object. This can be seen very easily when testing an extreme, e.g. a rotated loop.

    I would not recommend using the automatic rotation feature in this case (Full3D), but doing it manually with the waypoint rotation feature. This way, it is a bit more work to set up, but your objects will rotate exactly like you want them to. You can find more information on this in the documentation:
    https://flobuk.gitlab.io/assets/docs/unity/sws/movement/rotation#waypoint-rotation

    Not quite, some of the SetLookAt options are split into the LookAhead & LockRotation fields in the inspector. I can see that "stableZRotation" could come in handy, however I do not think it would fit to your use case.
     
    aer0ace likes this.
  35. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,513
    Definitely sounds like the best way to go to get the best visual results, but my plan was to generate the paths and banking in code. I suppose I can still rotate the waypoints during generation, based on some algorithm I described. Was just wondering if there was something already built in I might be able to use.
     
  36. unity_dev12345

    unity_dev12345

    Joined:
    Apr 13, 2021
    Posts:
    16
    I have just purchased this property, and before I start I would like to get some guidance on the player I want to move on automatic tracks in part of the game
    I have a player with all the scripts and movement on it, what do I need to integrate from this system for it to work?
     
  37. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    Hello @unity_dev12345, your question is a bit too broad for me to answer precisely. Simple Waypoint System comes with two different movement scripts and you will want to choose the one that works for your type of game. Please see the documentation for a description and when to use them:
    https://flobuk.gitlab.io/assets/docs/unity/sws/movement/scripts

    You will also want to look at all the sample scenes to find what out how they can be integrated.
     
  38. unity_dev12345

    unity_dev12345

    Joined:
    Apr 13, 2021
    Posts:
    16
    Thanks for the quick response, the asset looks great, I have another question: I put the script on my player and he walks nicely on the course, I wanted to ask what happens if in the middle of the course he suddenly decides to move to the side?
    I see that the whole route goes wrong (I used the option that only by pressing UP it continues to the next point)
    Is there something built into the system for such cases or does it have to end as soon as it gets on a track? (Then I have to stop any possibility of other movement)
     
  39. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    The movement scripts do automated movement, like an animation, on the path. You can tell the player object to start moving, pause and continue moving, but everything else needs to stop the movement. So, if you want the player object to move somewhere else (not on the path), you have to call Stop() on the movement script first.
     
  40. unity_dev12345

    unity_dev12345

    Joined:
    Apr 13, 2021
    Posts:
    16
    But my player does move in the middle of the path, how do I stop him? What is actually responsible for not being able to move with the arrows on the keyboard when automated movement ? (Or there is no such built-in option in the system and I have to create it)
     
  41. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    I am not sure what exactly you are referring to. As I said, if the object is moving without any user input (e.g. with the splineMove component), you can call Stop() on it to make it stop.

    If you are referring to example scene 6 or 8, Path Input / Camera Input, this is not automated movement. You are pressing keys to let the object move. If you want to stop the script receiving user input, you have to modify it depending on your requirement. For example, using a boolean variable that is set to false, to not continue with the code.
     
  42. NEOPOP

    NEOPOP

    Joined:
    Jan 19, 2017
    Posts:
    2
    hello. I'm currently making a game about planets.
    Can I use this asset to implement movement within a round but bumpy planet?
    If so, I really want to use it quickly!!
    I attached the planet path I wanted to create!
     

    Attached Files:

  43. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,290
    Hi @NEOPOP, thanks for your question. If you are looking for pathfinding, then this asset is not the right choice, since its pathfinding movement script is based on Unity navigation. That does not support orbital movement.

    If you would like to have fixed, pre-placed movement, you can do that with this asset using its path tweening.
     
    NEOPOP likes this.
  44. NEOPOP

    NEOPOP

    Joined:
    Jan 19, 2017
    Posts:
    2
    Yes, I will try this asset!! Thank you so much for the quick reply.