Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

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,187
    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:
    5
    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:
    5
    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,187
    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:
    5
    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,187
    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:
    5
    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,187
    @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,187
    @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,187
    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,187
    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,187
    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,187
    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,187
    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,187
    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:
    280
    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,187
    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:
    280
    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.