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.
  2. Dismiss Notice

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,152
    Hi @ryannotfound ! So you are a long-term SWS user? Thanks for that :)

    The current version offers events in a similar way, just not a list with one UnityEvent for each waypoint. Instead, this has been simplified to a single "Movement Change (int waypointIndex)" event. Please see the documentation for more details. Example scene 05-Events also has samples for this.

    The major change is that you would check for the waypoint index delivered to your method, before executing your code. So if you would like to execute something at every third waypoint, you would do

    Code (CSharp):
    1. if(waypointIndex % 3 == 0)
    2. {
    3.    //do your thing
    4. }
     
    ryannotfound likes this.
  2. ryannotfound

    ryannotfound

    Joined:
    May 5, 2016
    Posts:
    6
    Wonderful mate,
    Yup, getting back into UNITY and VR so thought i'd buy the new version, it's so good!
    I'm not a developer, so using ChatGPT to help clean up my code, and so far using it for a few Animal movements, and for things like assigning a single audio source to a gameobject, and using the path on a river so the sound will be always close to the player.

    Anyhow, thanks again, i'll keep playing with this more and give that a shot ;)
     
    Baroni likes this.
  3. desdinovait

    desdinovait

    Joined:
    Jan 3, 2020
    Posts:
    6
    Hi @Baroni is it possibile to move an object on a path while the path is children of another object that moving on path.
    Example: I move the planet on a path and on the planet there are rovers that moves on single paths
     
  4. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    Hi @desdinovait, yes, what you are describing is local movement. The example scene "04 Advanced" has a sample for this - an object moving on a rotating path, but it could also be moving as well.
     
  5. desdinovait

    desdinovait

    Joined:
    Jan 3, 2020
    Posts:
    6
    Thanks @Baroni , I checked your example but the local object is not on a path that move, but only child of a rotation object (local rotation). I need a child with a path that move on a parent with a path. I done some test and doesn't work, can you test it?
     
  6. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
  7. glazierjamie

    glazierjamie

    Joined:
    Jun 2, 2019
    Posts:
    2
    How do i get this script to update the Speed in the animator (Move controller)? I've attached spline move and set a speed of 1, but the animator doesnt seem to be reading this / setting the animation?
     
  8. desdinovait

    desdinovait

    Joined:
    Jan 3, 2020
    Posts:
    6
    @Baroni really thanks, i will check it out!
     
  9. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    Have a look at this documentation page, in the Animator section, mentioning the MoveAnimator component. That component sets the variables on the Animator Controller.
     
  10. glazierjamie

    glazierjamie

    Joined:
    Jun 2, 2019
    Posts:
    2
    Now i feel stupid - completely missed adding the animator script - thanks!
     
  11. watchagames

    watchagames

    Joined:
    Oct 1, 2017
    Posts:
    24
    Hi long time user, love the asset thanks for past support.
    Moving my game to 2022 from 2021.
    Works fine, just letting you know that looks like 2 sources are auto patched by unity:
    upload_2023-4-10_12-53-28.png


    Handles.FreeMoveHandle(wpPos, Quaternion.identity, size, Vector3.zero, (controlID, position, rotation, hSize, eventType) =>
    to
    var fmh_322_47_638167277267816693 = Quaternion.identity; Handles.FreeMoveHandle(wpPos, size, Vector3.zero, (controlID, position, rotation, hSize, eventType) =>

    Is this "normal" ?
    Thanks again
    Nicolas
     
  12. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    Hi @watchagames , thanks for the notice. The updated API seems to be the same as the old one, just without Quaternion.identity, which is never modified anyway.

    I am planning to do an update for 2022 LTS, but you can keep using it like that.
     
    watchagames likes this.
  13. Jaynesh

    Jaynesh

    Joined:
    Feb 28, 2015
    Posts:
    36
    Hi,

    Great product! Is it possible to get the current progress of the splineMove on the current path. e.g if the progress is half way, returning 50% or 0.5.
     
  14. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    Hi @Jaynesh , absolutely! You can use splineMove.tween.ElapsedPercentage() for this. That method is shipped with DOTween.
     
  15. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    596
    Hey i have a new question, ive been playing around with animating a path like in your Advanced example scene and it just wasn't working at all, the path only animated when the gameobject containing the path component itself was selected in the hierarchy.

    After some testing i realized that Standard paths can be animated but Bezier paths will not animate?

    Is this correct? and is there a way to make bezier paths animate or is this a limitation of the system?
    Its not the end of the world cause i can still animate basic lines and stuff, but beziers are really useful for nice curves, like even making a perfect looking circle using standard isn't quite as nice as with beziers.

    Also would have been nice if this information was in the docs haha, would have saved me some time testing lol

    I mean it seems like there should be a way since it DOES animate if the gameobject is selected, although i have no idea how that affects the unity editor regarding drawing the line renderer.
     
    Last edited: Apr 25, 2023
  16. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    Hi @luniac, due to performance reasons, bezier paths do not update every frame by default. When selected, the editor script does it though. Please see the CalculatePath() method in the API:

    https://flobuk.gitlab.io/assets/docs/sws/api/BezierPathManager.html

    Depending on the amount of waypoints and path detail, a reasonable update rate should be chosen (and not in Update()).
     
  17. spikezart

    spikezart

    Joined:
    Oct 28, 2021
    Posts:
    69
    Some feedback on the experimental waypoint rotation options. I wanted to use this to create a flight path for a plane that panned left and right as it turned.

    My plan was to have the plane flight straight and level waypoint 0 to waypoint 1, turn for waypoint 2 and then level out at waypoint 3 again. Waypoint 2 would have the plane 90 degrees on its side as it turned so that from waypoint 1 to waypoint 3 the plane would turn in and out of the bend.

    I couldn't get the bezier system to work for the bezier option as I couldn't see why the plane was moving at the wrong angle and turning around in flight but I'm getting nearer now with the normal spline option. However it was overly hard to configure. You have to select the path manager and then click on the waypoint you want to adjust, but have an arrow in view (bezier you can increase the frequency of them but not in the spline, so if you have a long path they are few and far between as well as small).

    Trying to configure each waypoint with tiny arrows that you can't access via the inspector and can only be configured indirectly is really hard and sometimes feels impossible to get all waypoints to work at the same time. In some instances I had the arrows flip between two points far from pointing straight ahead for some reason. Again with such a small arrow is hard to tune.

    The rotating waypoints to paths cause the arrows to look ahead past the next waypoint which doesn't match what a vehicle would do in this circumstance.

    Ive worked on this for a few days now and have for a while thought I am close to getting it working correctly only to find one adjustment makes other issues arise so I am thinking without a better way to adjust the directional arrows, and for further consideration for panning LR for flight paths it may be better to create a Unity timeline for this use case.

    Hope this helps.
     
  18. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    596
    What about at runtime? Im basically trying to recreate your local movement advanced path example where you had the path and object as children of a moving parent object.

    I don’t need to redraw the path, just to move it around and rotate it.
     
  19. AhmadKarim

    AhmadKarim

    Joined:
    Aug 17, 2022
    Posts:
    9
    Hello I just purchased the asset,

    I dont know why but I have a very weird problem. The waypoints system do not work, I press "P" and left click mouse to add one waypoint, it does not apply waypoint,

    The layers are default and the plane has mesh collider. Also, it creates another gameobject as "UnityForcesMeToDoThis (bug1394023)".

    I uploaded a video about the process Im am taking.



    Thank you very much for your help in advance
     
  20. AhmadKarim

    AhmadKarim

    Joined:
    Aug 17, 2022
    Posts:
    9
    As a side note, I tried version 2021, it works, I think when you added the empty gameobject in the recent version, the SWS does not work for 2020 version and older anymore, Please let me know, since my projects are all in Unity 2020 :(
     
  21. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    @spikezart Thank you for the feedback. However, considering that I did not receive feedback about this feature in the past year, in combination with the low asset price and you reducing your review specifically because of it (which to be honest I do find unfair, since it was clearly marked as experimental for a long time), I will think about reworking or removing it completely. A note though:

    This sounds to be more complicated than it is, in a regular use case. Arrows are not tiny, except when zoomed in so they do not clutter the whole screen. It is correct that each waypoint needs to be selected, but with the rotation transform tool selected as well, you can directly rotate the waypoint and the arrows will update accordingly displaying the predicted rotation. Alternatively you could directly rotate the waypoint, in the inspector - that's what the on-screen rotation transform does too, there is no magic to it.

    @luniac On bezier paths local movement works the same, did you set "Local Type = Path" on the movement script and made the moving object a child of the path? See: https://gifyu.com/image/Sleyj

    Hi @ahmadmohammadi that is weird, I am testing SWS on 2020.3.0f1 myself as a minimum compatible version and the path creation works. The additional game object is required due to a bug in more recent Unity versions, but having it does not "destroy" functionality on older versions like 2020. You should not press any mouse buttons while placing waypoints - only the P key on your keyboard for each new waypoint. If you click in between, waypoint placement will be cancelled.

    If that still does not work, have you tried resetting your Unity layout to default (dropdown in top right corner)?
     
    AhmadKarim likes this.
  22. AhmadKarim

    AhmadKarim

    Joined:
    Aug 17, 2022
    Posts:
    9

    Yes, I reseted Unity Layout to default and it works in all versions now. Thanks,
     
  23. AhmadKarim

    AhmadKarim

    Joined:
    Aug 17, 2022
    Posts:
    9
    Hello Sir, thanks for your great asset. I am just seeing that physics does not work with splineMove, I mean the object (e.g., a car) does not collide with other objects like another car, is there any way to consider this?
     
  24. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    That's by design and how the tweening library (DOTween) works in the movement script internally. You can have objects collide with each other and the OnTriggerEnter etc. methods are called correctly, but in order to have them affected by physics, you have to disable the movement script first. A movement script and physics cannot control one object at the same time - they would work against each other and just spin the object around like crazy.

    So, if you would like to have e.g. two cars collide with each other, you would use their OnTriggerEnter method to disable the movement script and then apply physics force to them manually.
     
  25. spikezart

    spikezart

    Joined:
    Oct 28, 2021
    Posts:
    69
    Up until now my feedback still states "Great product, great support." with ONE star reduced. I stated in my description the .."Experimental elements still need work." which is not unfair, it's true.

    I only gave this feedback in the asset store because I posted constructive criticism in this forum a few days ago for which you skipped over my post replying to others instead so expected no confirmation of my post.

    I've only just this week used the experimental features until this week so it's not my issue you've not been able to receive feedback a year ago.

    It seems there is a gap in the asset store for a decent flight waypoint system unless I am wrong so it would be a mistake to remove it from the asset.

    I will wait reworking or revise my feedback.
     
  26. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    I am confused - I reply to posts in the order they have been posted, with your post coming first in my last reply (see above), one day later, I did not skip it or replied to others here first.

    Absolutely, the asset definitely lacks functionality for fully supporting waypoints for a flight system with custom tilting etc., it is correct that it is quite difficult to get that right using the current feature set. I guess I was just referring to the review mentioning the "experimental" feature specifically, where in my definition of experimental, one would not expect it to fully work for all use cases and in production. Like for the Unity Tech releases, it is not assumed that they are 100% stable. I can see now where you are coming from (with the flight use case) and appreciate your follow up.
     
  27. Syoka

    Syoka

    Joined:
    Apr 15, 2018
    Posts:
    3
    Hello, I would like to ask: I created a path with two points by SWS.
    Could I partition it, without manually, into 5 waypoints with exactly equal distance?


    Thank you.
     
    Last edited: May 7, 2023
  28. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    Hi there!

    The exact solution would depend on your use case, since you did not mention whether you would want to layout the waypoints in the Unity Editor or at runtime. Or, if the 5 waypoints should be created by script too.

    Regardless, I can think of two options for this:
    - Waypoints are just game objects in the scene, as children of a PathManager component and game object. Therefore, for creating the additional waypoints, you could either write a runtime or editor script that measures the distance and direction from the first waypoint to the last waypoint, divides that by 5, adds new game objects in a loop at index * distance offset position and parents them to the PathManager game object. Lastly, call the Create() method on the PathManager to update it.
    - if you would like to do it in the Unity Editor but without a script, you can modify all waypoint positions at once using Numeric field expressions. For example, you could use that to layout all waypoints in a straight line, then rotate them in the direction you want them to be.

    Hope that helps.
     
  29. therabbitdied

    therabbitdied

    Joined:
    Jun 8, 2016
    Posts:
    4
    Hi,
    Great product. Works in 2021.3.16 but not in 2021.3.23. Tried everything I could think of. Reimported, set to default etc.
    It will not set the waypoints. Then it says not enough waypoints...cancelling. Also when I click to add waypoint manager this pops up, UnityForcesMeToDoThis (bug1394023).
     
  30. therabbitdied

    therabbitdied

    Joined:
    Jun 8, 2016
    Posts:
    4
    Not enough waypoints placed. Cancelling.
    UnityEngine.Debug:LogWarning (object)
    SWS.WaypointEditor:FinishPath () (at Assets/SimpleWaypointSystem/Scripts/Editor/WaypointEditor.cs:395)
    SWS.WaypointEditor:OnInspectorGUI () (at Assets/SimpleWaypointSystem/Scripts/Editor/WaypointEditor.cs:198)
    UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
     
  31. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    Hey @therabbitdied ! (poor rabbit)

    I have installed Unity 2021.3.25 this morning and tried to reproduce the issue without success. Starting from a new scene and adding a 3D plane, the WaypointManager, entering a path name and placing waypoints by pressing the 'P' key worked without issues.

    Did you do a side by side comparison and the exact same things in 2021.3.16 and 2021.3.23? Did you double check that your "ground" has a collider attached, or did you try out one of the example scenes for waypoint placement? Thank you for the additional details in advance.

    P.S. You can read more about bug 1394023 in the Unity 2022.2.0 release notes, basically Unity broke all OnDrawGizmos functions on an empty game object. That's why this kind of useless child game object exists as a fix.
     
  32. therabbitdied

    therabbitdied

    Joined:
    Jun 8, 2016
    Posts:
    4
    The only thing I didn't do was open a "fresh" project in that version. When I did, it worked flawlessly. I'm sorry to have wasted your time and I appreciate your response. It's something that I have done and can't figure out. But I will. As far the name "the rabbit died", hopefully, one day ,if I get finished on what I'm working, it will mean something totally different than what you think. Hopefully something good, not morbid. Thanks again.


    P.S. Google the phrase.
     
    Last edited: May 15, 2023
    Baroni likes this.
  33. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    Hi all,

    with Unity releasing the Splines package, interest in Simple Waypoint System has naturally declined in the past weeks and months. I am looking for ways to improve the added value of SWS, potentially when combining it with the Splines package, and would love to hear your feedback. What I can think of:

    - Replacing the WaypointManager and PathManager components with Splines package tools for Unity 2022.3+
    - Have the movement scripts (splineMove, navMove) make use of paths created with the Splines package
    - Add another movement script that makes use of Splines EvaluatePosition, C# Jobs and Burst compatible
    - Add another movement script that moves the object on the spline using physics

    Questions:
    - What do you think of the Splines package requirement?
    - Would you like to use "native" Splines movement or continue to use DOTween?
    - Any other feedback?

    Please feel free to post here or send me a message. Thanks!
     
  34. Karias361

    Karias361

    Joined:
    Sep 24, 2021
    Posts:
    4
    Hi, I have what I believe is an easy problem and maybe a common one too. I'm sure it's something stupid that I'm missing to do. I can't place my waypoints on the terrain or flat plain. They look like they are until I rotate the camera. I've checked out the demo scenes. Adding waypoints in there, work. But I cant find any special tag or layer that you might have used. I've read the manual like twenty times on getting started and FAQ's. Yes, they have colliders.
     
  35. Karias361

    Karias361

    Joined:
    Sep 24, 2021
    Posts:
    4
    Hi, hopefully an easy question. I cant get the waypoints to attach themselves on my terrain or a simple plain. They form in 3d space when I use "P". They work in the example scenes but I cant find a difference in what is in the Demo from my scenes. I didnt find any special tags or layers being used or mentioned in the Docs.
     
  36. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    Hi @Karias361, it's very difficult to tell remotely, maybe you could attach a screenshot of your terrain object, collider and where the waypoints are?

    The waypoint placement only uses raycasting from the viewport to mouse position and finds the "depth" in 3D space based on a collider that was hit. No extra tags, layers, or something like that - just an object with a collider. Maybe you have another collider somewhere in the scene that was hit, or you are not using a mesh collider but a box collider?
     
  37. Karias361

    Karias361

    Joined:
    Sep 24, 2021
    Posts:
    4
    No, it's just a mesh collider. I'm at work now, but I'll try to get you that screen shot when I get home if I still can't figure it out. I'll try it on a new scene. It wouldn't recognize a collider set to trigger, will it? I don't think any where near it but just checking.
     
  38. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    It does, both a collider with "Trigger" enabled or disabled works. Also, just checked that the Physics Collision Matrix on the project settings does not matter either.
     
  39. Karias361

    Karias361

    Joined:
    Sep 24, 2021
    Posts:
    4
    I got it! Around the terrain, I have a lake that goes underneath the terrain. The lake has a collider that triggers sound and swimming animation. Once I disabled that game object, bingo! Awesome, thanks.
     
  40. rexcheung

    rexcheung

    Joined:
    Feb 2, 2017
    Posts:
    35
    Hi, the asset is great and it helps me a lot.
    I got an questions. When the game is playing, i defined two paths. When switch path, the avatar will change rotation if the the two are in 180degree. I wonder if there is any method to make the switch path transit the avatar slowly so that the avatar would not seems to be "sudden change in rotation"
     
  41. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    Hi @rexcheung, thank you for your feedback and question. With "Move To Path" enabled on the movement script, set before switching paths, it will try to interpolate from the current position to the new path - however not immediately taking rotation into account, if the paths are in very different directions.

    For this, you will want to use a Coroutine that updates the object's rotation in LateUpdate (so after the "Move To Path" update happens) or via another separate tween (e.g. using DOTween's DORotate method). The reason this is not implemented is because of the very specific use cases, depending on the object moved being a humanoid, car, plane or of some other type, which would all have very different rotation requirements.
     
  42. beerbellybuffalo

    beerbellybuffalo

    Joined:
    May 8, 2020
    Posts:
    1
    Hi, love this asset!

    I have a question regarding Example 6 of the Sample Scenes provided, the one titled "Path Input".
    I want to achieve a similar result where movement is controlled by user input, so the setup in this example pretty much fits my use case perfectly. However, there is an issue where once the object has reached the end of the path, it gets stuck. Trying to move back in the opposite direction causes it to rotate on the spot repeatedly.

    As shown in the screenshot attached, this issue can be reproduced by moving to waypoint 5, and then trying to go back
    Any idea how to fix this?
     

    Attached Files:

  43. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    Hi @beerbellybuffalo, sorry for the delay as I am currently on vacation. I was able to reproduce this - the Console is spammed with hundreds of NullReferenceExceptions due to the tween being destroyed the object is moving on. I will provide a fix until Friday at the latest.
     
  44. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    Here are the promised fix instructions for the PathInputDemo script:
    - at line 30, insert: private Tweener tween;
    - in Start() at the end, insert: tween = move.tween;
    - in Update() at the beginning, insert: if (move.tween == null) move.tween = tween;
    - in LateUpdate() in the GetKey("left") call at the beginning, insert: if (progress <= 0) return;

    The fix will also be included in the next update. Thanks again for the report!
     
    beerbellybuffalo likes this.
  45. feylaputh

    feylaputh

    Joined:
    Aug 7, 2022
    Posts:
    2
    Hello, I am unable to install the Extension.

    I immediately got 4 compilation errors (attached file)

    I am in working on a URP project in VR, have you got an idea how to fix this?
    Thanks!
     

    Attached Files:

  46. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    Hello @feylaputh , thanks for the screenshot. Do you have a "Tools" class in your project that does not have its own namespace?
     
  47. jeff_wilkes1

    jeff_wilkes1

    Joined:
    Jul 2, 2020
    Posts:
    3
    Hello,
    this is a great asset but I am having a slight problem, It seems when i have multiple gameobjects trying to reach the same waypoint they are not able to actually get there and causes them keep moving towards the same waypoint but never actually moving from that point on. I am using the NavMove and have adjusted the radius of the nav mesh agent but still nothing. See in the below image all 3 NPC are trying to reach same waypoint (at least i believe thats what it is)

    Sorry if this has already been asked, i couldnt find anything.

    thanks
    upload_2023-8-10_8-42-29.png
     
  48. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    Hi Jeff, thanks for posting and the screenshot!

    You would want to increase the stoppingDistance on the NavMeshAgent too (see link for a good description on what it does). I guess your agents are pushing each other around the target destination, with no one being able to actually get close enough (controlled by stoppingDistance) to stop/continue movement. Let me know if that helped :)
     
  49. jeff_wilkes1

    jeff_wilkes1

    Joined:
    Jul 2, 2020
    Posts:
    3
    That seems to do it. thank you very much!
     
  50. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,152
    @jeff_wilkes1 Great! Please keep asking if there is something else, and leave a review on the Asset Store at some point in the future which would be much appreciated :)