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. markfrancombe

    markfrancombe

    Joined:
    May 26, 2009
    Posts:
    155
    Thanks @Baroni You were right that the update helped! Also seemed to fix my Idling character too... Only VERY SLIGHT issue I have now, is that she (my NPC) seems to occasionally go thru the geometry and seems to lean as hse turns alot. Cant quite figure out if its to do with the fact thats shes walking around a small hill, or if its her turning tahts doing it... but shes leaning OUT wards not in... needs a closer look.. As I said before, prob not a SWS issue, but as you probably have experienced many NPC related "fails" in testing your very fantastic package, I guess its not too cheeky to ask iof you have any clues.. youve been V helpful so far!
     
    Baroni likes this.
  2. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @markfrancombe thanks! Have you tried setting the lock rotation variable to X axis on the movement script of your character? That should fix the leaning as the rotation ignores turning sidewards then. Walking into the geometry is probably an issue with your path waypoint placement though.
     
  3. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297


    @Baroni,
    Found a weird bug. When using SplineMove script on a object without Rigidbody loop works fine and any object with rigidbody attached makes things bad. Try it yourself in the demo scene. Add rigidbody to a walker on loop example1. How can solve this issue ?. Need to have rigidbody in my scenario.
     
    Last edited: Mar 17, 2016
  4. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @sathya You are moving your object with a tween that manipulates the transform position and rotation. If you add a rigidbody to it which gets driven by gravity, of course this will interfere with the tween. Check isKinematic on the rigidbody and disable gravity as long as you are moving it via tweens.
     
  5. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297
    Understood. makes sense. Can you suggest something here. How can i make a traffic car move along path and still respond to player interaction which requires rigidbody and nonkinematic
     
  6. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297
  7. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @sathya Thanks for the screenshots. I can only guess that the gravity enabled rigidbody modifies the starting position of your object before the tween even starts, thus creating an additional control point at the first waypoint resulting in that short loop. You have several ways to combine colliders and rigidbodies, kinematic or non-kinematic and keep them reacting to each other (see collision matrix at the bottom): http://docs.unity3d.com/Manual/CollidersOverview.html

    I don't know your implementation details so I can't recommend something specific here.
     
    sathya likes this.
  8. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297
    Sure. I will try something on this and if it works i ll share it with the community. may be it will help others too.
     
  9. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    Love this system.

    But there seems to be a bug when adding waypoints between others.

    The new waypoints warp the path.

    See image.

    How do I fix this?
     

    Attached Files:

  10. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @reset Thanks for the screenshot. I can see hard edges on the path, is your game scale very low and the waypoints too close to each other by any chance?
    Also, bezier paths allow editing separate path segments to adjust their detail and further customize the path with handles, not like DOTweens automatic path smoothing you are seeing here.
     
  11. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297
    @Baroni,
    Hi is it possible at have multiple objects follow same path at different positions. Like multiple traffic vehicles on single path.
     
  12. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    That's what the startPoint variable on the movement script is for.
     
  13. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    Hi

    my car is orientated the wrong way along the path - not facing down the path.

    If I make the car a child of a cube and get the cube to follow the path the cube rotates 90 degrees.

    So I must make the car a child of another object and orientate the car to compensate?

    I already have a car in my scene following a path and this is not a child and is orientated perfectly.

    What could be the problem?

    thanks
     
    Last edited: Apr 3, 2016
  14. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @reset
    Your models have a different starting rotation. You could go back to your modelling application to fix it. Making them a child of another gameobject and rotating the child is a valid solution too.
     
  15. Smokas

    Smokas

    Joined:
    Mar 7, 2016
    Posts:
    114
    Hi,

    1. Is it possible to attach manually created or generated waypoints (e.g. EasyRoads 3D)?
    2. Is it possible to follow terrain height?
     
    Last edited: Apr 8, 2016
  16. Baroni

    Baroni

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

    1. Yes. You can assign any kind of gameobject to the PathManager in the inspector (list of waypoints) or assign them via code to its waypoints array.
    2. You will need to either place your waypoints exactly where you want them to be, or use our navMove script with pathfinding. Tweens are not designed for highly precise movement on uneven terrain, but pathfinding could do.
     
  17. txl_muc

    txl_muc

    Joined:
    May 1, 2014
    Posts:
    6
    Hi @Baroni,
    I am using SWS for some time now and I really like it! Thumbs up!
    Right now I am stuck a little bit, because I want to move an object along a closed path, controlling the speed of the movement using the SplineMove script. So far that works perfectly using the ChangeSpeed function, even with negative values. Now I would like the object jump to the end point of the closed path when the start point is reached during a backwards motion. But the object stops at the start point. Is that possible or do you know a practical workaround for that?
    Thanks a lot in advance for any advice!
    Felix
     
  18. Baroni

    Baroni

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

    in general, tweens are created for one loop on your path. You can move forwards and backwards on this tween, but not "exceed" its scope - i.e. let it automatically jump backwards to the end again. Have you tried enabling the "reverse" checkbox on the movement script, which just reverses the direction of your path?
     
  19. Smokas

    Smokas

    Joined:
    Mar 7, 2016
    Posts:
    114
    OK - you convinced me - bought your asset :)
     
    Baroni likes this.
  20. Smokas

    Smokas

    Joined:
    Mar 7, 2016
    Posts:
    114
    Got it working as I needed - added bulk import of waypoints.

    Screen Shot 2016-04-09 at 10.41.27.png
    Screen Shot 2016-04-09 at 10.41.40.png
    Screen Shot 2016-04-09 at 10.41.56.png
     
    Last edited: Apr 9, 2016
  21. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    Hi

    All moving objects in my scene use SWS.

    The camera is in a moving car using waypoints and is pursued by cars on waypoints.

    If my frame rate drops then the pursuit cars catch up - or overtake my car - which I don't want to happen. Everything is based on speed settings in SWS.

    In the end the whole scene is being rendered out to a 3D 360 video. So frame rate will drop massively.

    How do I make sure everything time like clockwork regardless of my frame rate?

    Cheers
     
  22. Baroni

    Baroni

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

    have you tried setting the update type to FixedUpdate in DOTweens settings?
     
  23. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    Haha thought that might be the case. Will explore. Cheers
     
  24. tapanij

    tapanij

    Joined:
    Oct 3, 2013
    Posts:
    1
    I have the following issue.
    I set runtime an event list and pathManager (splineMove.events = events and splineMove.pathContainer = sceneConfiguration.pathManager),
    then when I call splineMove.GoToWaypoint(120) and when it finishes OnWaypointReached() the index changes from 120 to 119. What could cause this?

    I can't see what the tweening does to the index because it's not open source. This happens when the speed is 5, but doesn't happen if it's 4 or 5.5.
    Here is my settings:
    http://imgur.com/LHEvqWK
    http://imgur.com/DG3LkJM
     
  25. C___

    C___

    Joined:
    Oct 15, 2014
    Posts:
    3
    related to samooJAM's issue:

    the spline move's speed is bugged.
    a way to reproduce what i am talking about is:

    1. open Example8_CameraInput.unity scene that comes with SWS asset
    2. select Walker game object in hierachy
    3. change Speed of SplineMove (Script) to something like 200
    4. play scene & press up to move the camera
    you will see that even though the Walker should pause movement at those Waypoints, it will actually pause at random positions instead.
    moreover, it's even more buggy when using a Bezier Path Type...

    i am not saying anyone would want to use 200 value for SplineMove.speed but I have issues with the events not being called at waypoints when using speed = 5.
     
    Last edited: Apr 22, 2016
  26. C___

    C___

    Joined:
    Oct 15, 2014
    Posts:
    3
    and here is a short gif showing what happens when i am pressing up key.
    did not stop at a single waypoint
     

    Attached Files:

    • r.gif
      r.gif
      File size:
      438.9 KB
      Views:
      888
  27. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    Note that the following things are better directed at DOTween but I will do my best to answer them.

    @samooJAM could you please send me a project that reproduces this to my email. I'm a little bit clueless which index you mean.

    @C___ The way DOTween calculates waypoint changes is by comparing the waypoint index and invoking OnWaypointChange on the next frame. With a very high speed, this could be a lot further along the path than the waypoint it was initially called for. Could you please verify that the events on the camera's movement script are set and available to be called.
     
  28. C___

    C___

    Joined:
    Oct 15, 2014
    Posts:
    3
    yes, the events on camera's movement script are set and available to be called.

    while trying to understand why the events assigned to a waypoint are not being called, i noticed that some waypoints are skipped. this was done debugging the SWS.SplineMove.cs script (ex. OnWaypointChange 5, then 6, then 8).
    however, it occurred even when using SplineMove.GoToWaypoint: i was passing index 10 as a parameter, and the Walker was being moved to index 9. (this is what @samooJAM was explaining, we are working on the same project).

    this situation appears not only at very high speeds, but mostly when using a Bezier Path Type.

    a work-around that seems to work well so far is making sure that when using a Bezier Path Type, the Handles are not too close to the Waypoints thus having less Path Detail around it and more Path Detail at the mid-way between 2 Waypoints. (see image attached)
     

    Attached Files:

    • a.jpg
      a.jpg
      File size:
      512.5 KB
      Views:
      758
  29. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @C___ Thank you for the additional explanation. As the OnWaypointChange callback is not something invoked by SWS, I will still need a project that reproduces this (please send it to our company email address). After further investigation, it is to be decided whether there is a workaround in SWS or if that's something handled by DOTween.
     
  30. imaewyn

    imaewyn

    Joined:
    Apr 23, 2016
    Posts:
    211
    There is two question about this super (really I like it) system...
    Is any way to paste together two splines? And how get bezier points (bPoints) in Script. in pathContainer i see only waypoints...
     
  31. imaewyn

    imaewyn

    Joined:
    Apr 23, 2016
    Posts:
    211
    and one more question. How I can moving the spline (in playing state) with the parent Object. I thought that toogle "local" responds for it. With it my object stopping to use moveSpline on the one place, but "local" give the strange effect on the animation itself
     
  32. Baroni

    Baroni

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

    - merging two splines would require you to either add more waypoints on the PathManager inspector and replace them with the waypoint gameobjects of your other path (then delete the unnecessary waypoints in the scene), or creating a short editor script that resizes the waypoints array of one PathManager and adds the other waypoint gameobjects. Currently there is no functionality that does this for you.
    - the bPoints list is a public variable of the BezierPathManager. See our scripting reference for all publicly available variables.
    - see the advanced example scene for a sample on how to use local paths. Your object with the movement scripts needs to be a child of the moving object too.
     
  33. imaewyn

    imaewyn

    Joined:
    Apr 23, 2016
    Posts:
    211
    Thank you! The issue was in my attempt was using 2 paths with one holder)))
     
  34. imaewyn

    imaewyn

    Joined:
    Apr 23, 2016
    Posts:
    211
    I've had some tests with splineMove and FPS controller. I can't find how to get rid of shaking. And it's not just because of the controller FPS (though I rewrote that position changed based on the position of the airplane - this is not the child). At the end of the video look at the tail

     
    Last edited: May 13, 2016
  35. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @imaewyn
    If you set a small value in "Look Ahead", e.g. 0.01 this will apply some smoothing to the path. If that doesn't help, note that "hard" position updates per frame in your code -especially on a FPS controller- are never expected to be 100% smooth.
     
  36. blamejane

    blamejane

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

    First let me start by saying congrats on your asset and excellent support. I think yours is the first asset that I've seen which has been around for so many years, and you still give excellent support! Most (in not all) assets I've seen to date, once the asset is over 2 years old we don't hear back from the dev. Anyway, keep up the good work.

    Bare with me here, I'm a complete newbie... I'm starting a new drone app where the drone needs to follow a path; which is why I'm looking at your asset. But I also need the drone to be affected by physics (wind, prop wash) while it's following a path . So I was looking at the drone/uav/helicopter flight sims/controller assets too. This is where I'm confused. Does it seem like I'm on the right track with the use of your asset in my app? Can I (or should I) combine it with a flight sim (to get the physics feature)? Any suggestions would be great. - Valerie
     
  37. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    Hi Valerie, thank you very much for following the progress of this asset and your kind words :)

    This asset uses a tweening engine (DOTween) to let objects move on paths, which use absolute position updates and these are not affected by physics or even ignore them - just like you would do a transform.Translate every frame. Unfortunately, the only way you could really simulate physics impact on a tween would be after pausing the tween / movement on the path - to let the physics take over. However, simulating wind can be done without physics on the moving object - you would attach the movement script on an empty game object, and have the actual drone a child of this object. Then do what ever you would like to add to the drone position or rotation, locally, while it (the parent object) still follows the path. I can't tell how other controller asset would work out with that - sorry!
     
  38. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    Thanks Baroni, what an elegant solution! It's almost too easy, I'm afraid to get excited in case I can't get it to work. Gonna give it a try and will let you know.
     
  39. blamejane

    blamejane

    Joined:
    Jul 8, 2013
    Posts:
    233
    I can't find a way to search this thread, so pardon me if this has already been asked...

    I created a basic path and have my game object following. I setup an event at waypoint 0 to play a wav file, then stop playing at the last waypoint. This was working good for a while, but then I did something and now waypoint 0 will not fire the event. I put an event at waypoint 1 and this successfully plays the wav. I've tried messing with the game object position relative to waypoint 0, I've tried toggling the Move to Path checkbox, hoping that would help. It didn't. I've tried duplicating waypoint 0, but this didn't help. I really don't want to have to start over creating my path/waypoints, and who's to say this won't happen again. Any suggestions?
     
  40. Boemak

    Boemak

    Joined:
    May 29, 2013
    Posts:
    48
    Hi,

    I've bought your asset and I have to say I am very impressed with it. One thing I am struggling with is switching paths.

    I want to create the following: I have one path for enemies to come into the level and after they have reached the end of this path I want them to patrol on a different path.

    I got it working with your EventCollisionTrigger script but now my ship jumps from the end of the last path to the new path. Is there a way to have this go more smoothly?

    This is the code I use on the last waypoint of the EnterLevelPath:

    Code (csharp):
    1.  
    2. void OnTriggerEnter(Colliderother)
    3. {
    4. if(!onTrigger)return;
    5. print("WaypointTrigger!");
    6. var newPath = WaypointManager.Paths["Patrol1"];
    7. var mover= other.GetComponent<splineMove>();
    8. mover.SetPath(newPath);
    9. mover.moveToPath=true;
    10. mover.loopType=splineMove.LoopType.loop;
    11.  
    12. mover.closeLoop=true;
    13. //dosomethingheredirectly,
    14. //orassigneventmethodsinthe inspector[/INDENT]
    15.  
    16. myEvent.Invoke();[/INDENT]
    17. }
    18.  
    The closeLoop is also problematic in that it is also going erratic. Is there anything I can do about this?
     
  41. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    I'm usually very bad at taking a guess in projects that are not mine, without seeing code or anything :) Could you please send me a project that reproduces this to my email (last page in documentation pdf).

    Hi there, thanks for using SWS! Calling SetPath with the new PathManager component will initiate the new walk routine immediately. As you are setting moveToPath and some other options afterwards, these could be ignored. Please call moveToPath = true, loopType etc. before SetPath. Let's see if that will result in the expected behavior.
     
  42. Boemak

    Boemak

    Joined:
    May 29, 2013
    Posts:
    48
    Hi, Thanks for the reply, on a Saturday no less ;)
    That does not seem to fix it.

    How would the walker know where to go if the second path had not been loaded yet?

    The example in the runtimeDemo exhibits the behaviour I am looking for, the walker walks smoothly from one path to the other.

    Edit: A difference I found in the examples is the MoveAnimator script being loaded on the Walker, does this handle the movement?

    Thanks for your time.
     
  43. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @Boemak
    The example scene uses the same approach, additionally it checks the current path and sets the opposite (to allow for switching between them all the time). In the stripped down version:
    Code (csharp):
    1. moveRef.moveToPath = true;
    2. moveRef.SetPath(WaypointManager.Paths[pathName]);

    moveToPath is a flag on the movement script, it doesn't actually find anything before the path gets started. But when you switch paths, in this moment the flag is considered and the object knows it should walk to the first waypoint (or the waypoint you set in the "startPoint" variable) on the new path. Could you also try to remove the closeLoop = true line for a moment and see if that changes something.

    Edit to answer your edit: MoveAnimator sets Mecanim animations based on the walker's speed and direction, it does not affect movement in any way.
     
    Last edited: May 21, 2016
  44. Boemak

    Boemak

    Joined:
    May 29, 2013
    Posts:
    48
    Well, I've rebuilt everything in a test scene and now it works like I thought it would. I've no clue as to why it did not work in my other scene. I haven't even changed the scripts.

    Any ideas?
     
  45. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    As much as I would like to, my crystal ball is turned off on weekends :)
     
  46. Boemak

    Boemak

    Joined:
    May 29, 2013
    Posts:
    48
    For shame ;) I will keep an eye out. Thanks for the help so far and keep up the good work!
     
  47. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    Use this link.
     
    Baroni likes this.
  48. Boemak

    Boemak

    Joined:
    May 29, 2013
    Posts:
    48
    Ok, I can't wrap my head around "local" tweening.

    I want my enemy to follow a path and also move a little up and down ( hovering ). So my thoughts are to make two animation paths. The first for the path movement and the second for the up and down.

    So I've been reading and I think I need "local" so that the "hovering" tweening is calculated from the position right now.

    How do I get this to work? Does my path following also need to be parented to my enemy so it moves along with it?

    I've searched ( thanks for the above link BTW ) but it is still not clear.

    I thought that instead of using the coordinates from the path to calculate the position it would calculate the position using the objects coordinates as starting point.
     
  49. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    It's the other way around, the moving object needs to be parented to the path, so you can move the path and all moving objects keep their relative position. Please have a look at the advanced example scene, where there's a sample for a local moving object (the rotating path with a sphere on it).

    No, it doesn't, as the path still provides all position updates to the moving object. I think what you are looking for is having two game objects - the parent with the movement script, and the child positioned where you want it to be.
     
  50. Boemak

    Boemak

    Joined:
    May 29, 2013
    Posts:
    48
    I don't know if this is the way, but it works. I've created a second path for the sideways movement and gave this a splineMover following the first path. So now the second path is moving along the first path.

    This seems to work.....