Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Simple Waypoint System (SWS) - Move objects along paths

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

  1. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    How did you get/create that link?
     
  2. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    Magic ;-)
     
  3. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    c'mon aren't you gonna teach me?
     
  4. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    Sure. Hint: Look at the URL for the link and then look at the URL for this thread.
     
  5. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    Thanks!!
     
    Tinjaw likes this.
  6. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    Hi Baroni,

    Thanks for your excellent waypoint system. I haven't rated it yet, but I plan on with 5 stars (regardless of my question). Your asset and continued support of it are worthy of 5 stars!!

    I would like to add my own "user points" at locations on the path. They are only for purposes of my game, not to affect the path. I want to add x number of these user points, distributing them evenly down the length of the path. To me, they are similar to your bezier detail points. I already have the total path length via the PathManager and WaypointManager.GetPathLength. With the path length I wanted to calc the distribution/spacing of my user points. Again I don't want to re-invent the wheel here, so I thought I'd ask about your bezier detail points and see if you had suggestions for me.

    Again, I can't say enough about SWS; but then I'm sure you already know that :)
     
  7. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @blamejane :)

    That's a good question! If your path points (the points between waypoints) are distributed evenly on the path, you could get a path point by accessing the pathPoints array at runtime (GetPathPoints() of a BezierManager). So if you would have a method that calculates a percentage at which you would like to place waypoints at (e.g. 1 object = 0.5%, 2 objects = 0.33%, 0.66%, 3 objects = 0.25%, 0.5%, 0.75% and so on) you could get the path point of the pathPoints array which relates to the calculated percentage (array length * percentage = array index to place the object at). This is just one idea that came to my mind. There are possibly numerous different approaches to get this done, but I hope that helps!
     
  8. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    Thanks, that worked great. I'm super glad I asked before trying to figure something out. Such an elegant solution.
     
  9. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    Another quick question if you don't mind...

    My "user points", which have been distributed along the path at even intervals, are actually flat panels (not cubes or spheres). So the problem I'm having is that sometimes (depending on the direction of the path) the panel display at certain user points is not perpendicular to the path. This means that anything displayed on them can't be scene.

    Do you know an easy way for me to make sure the panels are perpendicular to the path?

    Thanks Baroni
     
  10. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @blamejane
    Maybe a solution would be to get the last and next bezier point on the path, and have the actual user point object (positioned between those two) rotated to face the "up" direction of those two points (by calculating the direction from last to next point, then rotating by 90 degrees).

    Oh and thank you very much for the review :)
     
  11. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    That was it, thanks again!
     
  12. VirtualisDev

    VirtualisDev

    Joined:
    Jul 21, 2015
    Posts:
    30
    Hello,


    Is it suitable for multiple agents in one path with steering/avoidance between them ?
     
  13. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @Timothee35 If you are using Unity's NavMesh with our navMove script, the agents have an avoidance priority which can be set up in the inspector. Usually they should avoid each other with different priorities. The other movement script (splineMove) is "fixed" to the path so it doesn't work that well with avoidance. A workaround for that would be to have the movement script on a parent, and let the child avoid others by raycasting and manipulating its local position only.
     
  14. VirtualisDev

    VirtualisDev

    Joined:
    Jul 21, 2015
    Posts:
    30
    Thanks,


    We'll try this !
     
  15. martire

    martire

    Joined:
    Feb 27, 2015
    Posts:
    35
    Hi!
    I'm using SWS and it is great!
    However, I have more or less 50 guys walking on my scene but, after a while, 8 of them stop walking and I receive this message:

    FormatException: Input string was not in the correct format
    System.Int32.Parse (System.String s) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Int32.cs:629)
    SWS.navMove+<NextWaypoint>c__Iterator3B.MoveNext () (at Assets/SWS/Scripts/Movement/navMove.cs:197)



    Could you give me some help on that, please?

    Thanks!
     
    Last edited: May 30, 2016
  16. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    Hi @martire, could you please send a stripped down project that reproduces this to my email (last page in documentation pdf)? I'm a bit short on time due to fiscal year end, but I'll take a look at it this week.
     
  17. martire

    martire

    Joined:
    Feb 27, 2015
    Posts:
    35
    Oh, don't worry. I just deleted the Waypoint and created a new one. Everything is doing fine now!

    Thanks :)
     
  18. cranecam

    cranecam

    Joined:
    Nov 25, 2013
    Posts:
    25
    hi,
    I would like to use the SWS to move a character (with a rigidbody, gravity disabled) along a roof of building, then at the edge, enable rigidbody and give the person a force so it sort of "jumps" off. Any tips on how to set this up so it looks "fluid"..I am struggling with a jerky movement...maybe something to do with abrupt stop of the tween in the background...
     
  19. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    Hi @cranecam,

    did you check the events example scene? There is a character that when it collides with a wall, gets added some explosion force to it. I guess that's basically the same but it depends on the force you are adding.
     
  20. DavidHw

    DavidHw

    Joined:
    Mar 4, 2015
    Posts:
    8
    Hi just bought SWS, and have a question, what I want to do is have an object that moves around at run time with a spline move script on it, then when it hits a collision point it is then told to follow the SWS set path. I have set it up so when it hits a collision mesh it is told what path to follow and to move to that path and the spline move script updates on the object with the path name and move to information. But the object fails to follow the path ? can SWS do this or am I missing something ? The reason for wanting this behavior is the object will move along straight lines using physics, then when it comes to curves SWS with steer it round them accurately, after the curve it then again moves in straight lines with physics until it comes to the next curve where again I want to tell it to use the next SWS path and so on and so on. If I set the objects spline move script to show the on start ticked, Move to path ticked and the Path container field filled prior to run time, it works fine and follows the path far better than iTween attempts did so like that bit.
     
  21. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    Hi @DavidHw, thanks for using SWS!

    Are you calling the SetPath method with the PathManager object you want to follow? Could you please post the code snippet where you are switching to the path and set all these things. The runtime example scene has a sample on how to switch paths from one to the other (or start following them), so I'm not sure of your exact project setup.
     
  22. DavidHw

    DavidHw

    Joined:
    Mar 4, 2015
    Posts:
    8
    Hi thanks for reply, I should never ask a question till you have sleep on it :) the paths are child objects of my curved geometry, so when I copy the curves and put them where I want in my scene they have the path already set up for them..but I forgot that the path name remains the same so each copy has the same path name as a child, If I rename each path it works as it should,and the trigger sets the correct path name, it was trying to work but gets very confused with all the paths use the same name. So now it works as it should the walker hits a trigger is told what path to move around which it does on completion it moves via physics until it meets the next trigger all good. My next problem is I want more than one walker following the paths, which when I added a second it caused problems as soon as one walker hits a trigger they both move towards that path to follow it :(. The end goal is to have a spawn er that generates walkers and they follow my layout and curves, not sure if that is possible yet spawned objects don't seem to get the set path instruction as they have a (clone) after there name so SWS_set Path ,walker object is set to Walker test, but in reality at run time the actual name given when spawned is Walker test (clone)
     
  23. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @DavidHw are you using PlayMaker? I'm not familiar with how PlayMaker works, but you should be able to get the instantiated walkers and call SetPath on them. Make sure to disable "OnStart" on the walker prefab, because you are obviously controlling that by script/actions. The issue with both characters following the new path is probably a logical problem in your method workflow so I'm not able to give advices on that.
     
  24. DavidHw

    DavidHw

    Joined:
    Mar 4, 2015
    Posts:
    8
    Hi, Yes I am using Playmaker , the Playmaker "SWS_set Path" is that not part of your package ? I have got round the naming problem by renaming the spawned items once spawned, but the Playmaker SWS_set Path action still fails with "sendmessage Setpath has no receiver" as it doesn't recognize a spawned item to change it's properties, works fine with a non spawned item including the name change setup.. If I use iTween and the same setup and FSM's but replace SWS set path with itween move, then it all works with spawned items so in theory the logic is good, it only fails once I used the SWS-set Path.
     
  25. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @DavidHw it is part of the package, but I can't help with how PlayMaker works. You'll have to contact PlayMaker support for PlayMaker specific issues - like how to reference a gameobject created at runtime.
     
  26. DavidHw

    DavidHw

    Joined:
    Mar 4, 2015
    Posts:
    8
    Hi thanks for reply so have you tested the Playmaker parts of your package ? I am not asking for Playmaker support just want to known that the Playmaker parts in your package have been tested and that they work, the rest I will figure out.
     
  27. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    They work. The message you are seeing occurs because you didn't specify a target for the SetPath action.
     
  28. ScottyDSB

    ScottyDSB

    Joined:
    Mar 18, 2016
    Posts:
    124
    Hello, just a silly question I´m newbie with this stuff and I don´t find the answer. How to get that a path follows an object? I want a path so the player when moves the path moves with him, so the enemies are always around the player. I don´t find how to do it. Should I move the x z points of every waypoint?
     
  29. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @icampomanes Hi, please have a look at the "Local" sample in the advanced example scene. There is a ball following a rotating path. This is the approach you're going to use - toggle the "local" checkbox on the enemies' movement script and make your enemies children of the path. Then parent the path to the player.
     
  30. ScottyDSB

    ScottyDSB

    Joined:
    Mar 18, 2016
    Posts:
    124
    Hey that was fast, thank you very much, this is a great asset and support!
     
  31. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    Hi Baroni,

    I was researching this thread looking for flight path "barrel rolls" type support and came across your reply...

    I was curious if this has made it into one of your demos...seems like you show everything, figured I'd ask :)
     
  32. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    Hey @blamejane, unfortunately a sample for this dropped of my to-do list it seems. Thanks for the reminder, could be fun to implement for the next update (which still needs a little bit more time, so feel free to go ahead)!
     
  33. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    Okay thanks. I did notice a problem that I wasn't sure about. To reproduce,

    NOTE: Now when I run the steps below everything works fine for standard paths, but bezier paths events are wrong when path detail number is low (say 1 instead of 5)...

    1. load Example5_Events scene
    2. add a script to every waypoint in Path1-1 (Delay). In the script create a method that logs the waypoint game object name to the console.
    3. Show events for the Walker for this path
    4. Add an event for each waypoint that calls your new script method (step #2 above)
    5. Run the app.

    For some reason the events are called like so (0,1,2,3,4,0,5). Notice the "0" between 4 and 5. See attached image:

    I have verified that I am calling the correct events, I've created several test paths of my own and to add to the confusion, if you create a bezier path, increasing the path "detail" points helps. On some paths, having path details points set to 1 causes this event fire problem, but up the detail to 5 and the problem goes away. On screen the follow object follows the path correctly, but events log differently. I'll keep looking at this, but I really think it's a bug at this point. Just fyi.
     

    Attached Files:

    Last edited: Jun 5, 2016
  34. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    I did some additional research, trying to figure out why bezier waypoint events are called out of order. So far it seems that if the spline movement Time Value is set to Speed then the events are firing correctly. If Time Value is set to Time and the Ease Value is In Out Cubic, then my events fire incorrectly.

    UPDATE: Speed settings produce incorrect results as well. Attached are screen shots where the only change made is to the speed. If you look they both contain missing events.

    Screen Shot 2016-06-05 at 10.07.34 AM.png Screen Shot 2016-06-05 at 10.06.53 AM.png
     
    Last edited: Jun 5, 2016
  35. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @blamejane Thanks for taking a deep look at this, I'm going to investigate the situation shortly. Regarding the speed increase: Simple Waypoint System gets the waypoint callback by DOTween, so I guess that with a high speed variable, the moving object does not "land" on the waypoint exactly and thus the event is not being fired.

    I can see that you are using a high position value for your object to be placed at (x = 200, z = 160, etc.) which could be an issue too. Could you possibly send me a minimum project that reproduces these things via email: info [at] rebound-games [dot] com.
     
  36. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    @Baroni thanks just sent an email. Let me know what you think.
     
  37. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    So are the events going to be consistent? I'm seeing random waypoint events being skipped, and different waypoints each time. Just curious if this is the way it's going to be.
     
  38. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @blamejane Sorry for the delay, I've just had a chance to look at your project (thanks for that, btw). I've put a Debug.Log(index) in splineMove's OnWaypointChange method, which gets called by DOTween directly. The result was more or less expected, see the attached image.

    Some of the points are skipped completely, while it gets more reliable the slower an object moves. This is what I've described in my last post too. As this is not something controlled by SWS but a method invoked by DOTween (which SWS hooks into), we could try to raise this with the developer of DOTween for a possible fix. Please let me know if you would like to send him an email with the same project or if I should get in touch.
     

    Attached Files:

  39. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    Thanks Baroni, glad to hear it isn't anything with my work or yours :)

    Please go ahead and send the DOTween developer whatever information you have as well as the project I sent you. Maybe we'll get lucky; fingers-crossed.
     
  40. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @blamejane I've tried to strip down your project to only use DOTween and nothing else, got a repro of both bugs (events being skipped and waypoint 0 called at the end of a path). Then before preparing an email, I've updated to the latest version of DOTween... which to my pleasant surprise contains fixes for both things! Found this in one of the release notes:

    DOTween v1.1.200 (March 18, 2016)
    BUGFIX: Fixed OnWaypointChange being called only once even if the tween went through multiple waypoints since the last update

    I couldn't find an explicit entry for the second bug, but it's not reproducible anymore. Please update to at least DOTween v1.1.200 or newer and try running it.
     
  41. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    Is it possible to destroy and re-instantiate a walker and it's path when the walker reaches the terminal waypoint? Basically an endless loop without using the reset function in SWS...
     
  42. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @buttmatrix You could use an event for that. Add one at the last waypoint at runtime and then every time you create the new path. Your script cant be attached to the walker or path though if you are destroying these.
     
  43. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    Could you provide any suggestions about which event or how you (personally) might do this? I'm tinkering with set.active ATM.
     
  44. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @buttmatrix
    I'm wouldnt use a Unity method and just write a short script that does all I want, then link the event to this method in my own script. Depending on what you want to do, calling Stop() on the movement script and Destroy() on the Walker afterwards could work out.
     
  45. Aranda

    Aranda

    Joined:
    Jan 23, 2015
    Posts:
    16
    HI @Baroni, thank for the very useful asset!. I just wanted to report a (minor) bug:

    When setting `splineMove` to use `TimeValue.speed`, we don't get to control the easing. I guess this is because it only makes sense to use linear easing on speed based paths. So the problem occurs if you switch to `TimeValue.time`, then change the ease type to somethign other than Linear, then switch back to `TimeValue.speed`. Now you get unexpected behaviour on your path, and it can be pretty tricky to figure out why if you don't remember adjusting the easing! :)
     
  46. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
  47. darryldmps

    darryldmps

    Joined:
    Mar 11, 2015
    Posts:
    6
    Hi Baroni,
    When switching between paths, using the same approach as in the runtime example, I'm experiencing a significant judder/shake when moving to the next path (move to path option is true). The judder is most significant when moving from the end of the previous path and upon reaching the start of the new path. It appears to be something to do with the game object reorientating or snapping to the new confidantes. Have you encountered this, and can you offer some advice on a solution?. Many thanks.
     
  48. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    Hi @darryldmps,

    once a gameobject reaches a new path, DOTween takes over and orients the object to face the path (if set in the path mode). This transition can be rough indeed, depending on the old and new rotation values. The moveToPath option tries to make that more smooth, but it doesn't work in all cases. I've got several requests to improve the transition and will give this more priority for the next update. For now, a workaround could be to make your own rotation coroutine on the switch that offers more manual control.
     
  49. ikonakona

    ikonakona

    Joined:
    Jun 28, 2016
    Posts:
    4
    This package got my enemies moving quickly for my prototype. Great job!

    I do have a question about making characters jump. I've looked through this thread and it seem the best way is to move the child object in local space in the y-direction. I'm having an issue when I want to jump to new elevations using splineMove. If the object is moving at constant speed and "jumps down", it's speed in the X-Z plane changes. I'm assuming it's because it maintains its speed in 3D so the projected velocity on the X-Z plane is less.

    Is there a way for me to make a character jump up and down to different elevations? I have my waypoints setup like the 2D example in Advanced. Maybe I have to use navMeshes, but I really like how smoothly I can make characters turn with curves and the fact that characters won't try to take the shortest path every time (I don't like characters hugging corners).
     
  50. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @ikonakona thanks for using SWS! Right, if your game camera is oriented more in a 2D perspective, then even with constant speed it could look like your object is moving slower when only moving in the depth of the camera.

    As for the elevations, you could have a constant value that defines the current y position of your object. Modifying the local y position (of the child) would be the correct approach. Then e.g. when the players enters a trigger, raise the y value to the new height. If it jumps and falls down, let the player object transition to this y value (instead of 0 again) so it stays on that height.

    Hope that helps!