Search Unity

Simple Waypoint System (SWS) - Move objects along paths

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

  1. robdeja

    robdeja

    Joined:
    Mar 18, 2016
    Posts:
    7
    Ok thanks, that make sense.

    Thanks for the quick reply,
    Rob.
     
  2. DevilDarkSlayer

    DevilDarkSlayer

    Joined:
    Oct 11, 2017
    Posts:
    6
    Hi,
    i'm writing this post because i think that i need help.
    First of all sorry if i made mistake in english, it's not my language, but i'll do my best.

    I'm working on a 2.5D game with different paths, and i'm having troubles in changing paths.
    This is my scene: i have two paths (bezier): the green one, and the red one.




    I have a collider and if i press "up" in the collider, my character goes on the green path. If i press down, he goes on the red path.

    I have no problem to change the path, but when i do that he starts to act in a strange way and i can't figure how why.

    this is the code when i change paths:

    Code (CSharp):
    1.  
    2.     private void OnTriggerStay(Collider other)
    3.     {
    4.         if (other.gameObject.name == "PlayerFoot")
    5.         {
    6.             if(Time.time > m_fPauseTime)
    7.             {
    8.                 m_fPathChosen = Input.GetAxis("Vertical");
    9.                 if (m_fPathChosen > 0)
    10.                 {
    11.                
    12.                     m_cSplineMove.SetPath(m_pmUpperPath);
    13.                     m_cSplineMove.GoToWaypoint(m_iUpperStartPoint);
    14.                     GameObject.Find("Player").GetComponent<HorizontalMovement>().m_fProgress = m_cSplineMove.tween.fullPosition;
    15.                     m_fPauseTime = Time.time + 0.5f;
    16.                 }
    17.                 else if (m_fPathChosen < 0)
    18.                 {
    19.                
    20.                     m_cSplineMove.SetPath(m_pmBottomPath);
    21.                     m_cSplineMove.GoToWaypoint(m_iBottomStartPoint);
    22.                     GameObject.Find("Player").GetComponent<HorizontalMovement>().m_fProgress = m_cSplineMove.tween.fullPosition;
    23.                     m_fPauseTime = Time.time + 0.5f;
    24.                 }
    25.             }
    26.         }
    27.     }
    Here the link for the video of the acting of the character after i change path.

    http://www.mediafire.com/file/1y650tc9z4ocsvn/video-1515943763.mp4


    I hope someone can help me. Thank you very much.
     
  3. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi @UDN_aac78bb9-e469-492e-8007-709da4ce2b72,

    what is the HorizontalMovement script doing there? It seems that in your video, there is another movement script manipulating the character, so it goes back and forth... I hope you understand that I cannot make a more precise assumption by watching your video. If you would like me to investigate your project, please send me a minimal repro project (e.g. only the character and paths, no environment) to our support email address.
     
  4. DevilDarkSlayer

    DevilDarkSlayer

    Joined:
    Oct 11, 2017
    Posts:
    6
    Hi Baroni,
    thank you very much for the quick reply.
    I'm sorry, i forgot to explain the HorizontalMovement.
    He is the manager of the Player movement.
    No problem, i can put here the code:

    Code (CSharp):
    1.    m_fPlayerSpeed = Input.GetAxis("Horizontal");
    2.         m_aAnimator.SetFloat("Speed", Math.Abs(m_fPlayerSpeed));
    3.  
    4.         m_fTweenDuration = m_cSplineMove.tween.Duration();
    5.  
    6.         //Rotate character in the direction they're moving
    7.         if (m_fPlayerSpeed != 0)
    8.         {
    9.             if (m_fPlayerSpeed > 0)
    10.             {
    11.                 m_fProgress += Time.deltaTime * Math.Abs(m_fPlayerSpeed) * GetSpeed();
    12.                 m_fProgress = Mathf.Clamp(m_fProgress, 0, m_fTweenDuration);
    13.                 m_cSplineMove.tween.fullPosition = m_fProgress;
    14.                 m_enPlayerSide = PLAYER_SIDE.PS_RIGHT;
    15.             }
    16.             else if (m_fPlayerSpeed < 0)
    17.             {
    18.                 m_fProgress -= Time.deltaTime * Math.Abs(m_fPlayerSpeed) * GetSpeed();
    19.                 m_fProgress = Mathf.Clamp(m_fProgress, 0, m_fTweenDuration);
    20.                 m_cSplineMove.tween.fullPosition = m_fProgress;
    21.                 m_enPlayerSide = PLAYER_SIDE.PS_LEFT;
    22.  
    23.                 m_vRotation = transform.localEulerAngles;
    24.                 m_vRotation.y += 180;
    25.                 transform.localEulerAngles = m_vRotation;
    26.             }
    27.         }
    28. }
    here the horizontal input parameters:


    If this code can't help you, i can send you a little project.
    But i need your mail :)
    Thank you very much
     
    Last edited: Jan 15, 2018
  5. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Thanks for the code snippet. I can see that you are manipulating the movement tween via two scripts at the same time indeed - the default splineMove script, and your HorizontalMovement script. By calling SetPath and GoToWaypoint on the splineMove script, it does start the tween already (see the scripting reference) and let's your object move on the path. So you have a tween running for your object, controlled by the splineMove script. Next, you are manipulating the position of the character on the path by setting tween.fullPosition in your own script. This does overwrite the character's position to some extent, but the splineMove script is still running after all.

    -> You have to decide whether you would like to control the position manually, via tween.fullPosition, or keep it automated by the splineMove script. In case you want the first, you have to initialize the path on the splineMove script, but can call .Pause() on it afterwards to not interfere with your manual position setter.
     
  6. DevilDarkSlayer

    DevilDarkSlayer

    Joined:
    Oct 11, 2017
    Posts:
    6
    Mmm,
    i'm not sure i understand very well :D

    Are you telling me i have to deactivate horizontalcontrol before switch the paths?


    Code (CSharp):
    1.  
    2.  private void OnTriggerStay(Collider other)
    3.     {
    4.         if (other.gameObject.name == "PlayerFoot")
    5.         {
    6.             if (Time.time > m_fPauseTime)
    7.             {
    8.                 m_fPathChosen = Input.GetAxis("Vertical");
    9.                 if (m_fPathChosen > 0)
    10.                 {
    11.                     GameObject.Find("Player").GetComponent<HorizontalMovement>().enabled = false;
    12.                     m_cSplineMove.enabled = false;
    13.                     m_cSplineMove.SetPath(m_pmUpperPath);
    14.                     m_cSplineMove.GoToWaypoint(m_iUpperStartPoint);
    15.                     GameObject.Find("Player").GetComponent<HorizontalMovement>().m_fProgress = m_cSplineMove.tween.fullPosition;
    16.                     //      GameObject.Find("Player").GetComponent<HorizontalMovement>().enabled = true;
    17.                     //m_cSplineMove.enabled = true;
    18.                     m_fPauseTime = Time.time + 0.5f;
    19.                 }
    20.                 else if (m_fPathChosen < 0)
    21.                 {
    22.                     GameObject.Find("Player").GetComponent<HorizontalMovement>().enabled = false;
    23.                     m_cSplineMove.enabled = false;
    24.                     m_cSplineMove.SetPath(m_pmBottomPath);
    25.                     m_cSplineMove.GoToWaypoint(m_iBottomStartPoint);
    26.                     GameObject.Find("Player").GetComponent<HorizontalMovement>().m_fProgress = m_cSplineMove.tween.fullPosition;
    27.                     //    GameObject.Find("Player").GetComponent<HorizontalMovement>().enabled = true;
    28.                     //m_cSplineMove.enabled = true;
    29.                     m_fPauseTime = Time.time + 0.5f;
    30.                 }
    31.             }
    32.         }
    33.     }
    34.  
    I just tried this, but he starts to "moonwalk" and of course after i cant move (because i put a comment on the other enabled = true)

    I'm sorry but i can't figure how to solve this bug :(
     
  7. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    You have to deactivate one of your movement scripts. You can't control the object with the automatic tween (splineMove) and your custom input (HorizontalMovement) at the same time.

    Quoted this because you added splineMove.enabled = false, which does not pause the tween. Calling .Pause() on splineMove does pause the tween - after you called SetPath!
     
  8. keln

    keln

    Joined:
    Oct 28, 2016
    Posts:
    2
    Hello! I'm interested in buying the asset, but I need to know if it can work with my project.

    I'm already using the path system on DOTween, but I can't really change waypoints in the middle of the movement easily without doing shenaningans. I'm trying to do a trafic simulation, where cars can change their waypoint depending on the road situation, so they don't go through eachother like there are no more cars, do you think your asset can help me on that?

    Here is a example were I'm trying to change paths in runtime, failing miserably...

    https://gyazo.com/2abf72676da76350605e5d7a49bfa309

    I don't really need the part of visual scripting, I need the asset to be capable of changuing waypoints on runtime, from a list of Vector3 as waypoints.

    Thank you!.
     
  9. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi @keln,

    since SWS uses DOTween internally, the same restrictions apply regarding changing waypoints at runtime: positions can't be changed, except you start the tween from the beginning. There is no need to change the waypoints of the movement script at runtime though - you would have two paths (one going all the way left, one starting mid path 1 going right). Then you can trigger the object at a waypoint to switch to the other path, starting at the waypoint it left off.

    There are several customers using SWS in a traffic simulation app that way.
     
  10. keln

    keln

    Joined:
    Oct 28, 2016
    Posts:
    2
    I have that working, when it finish the path, it goes to the next path with new waypoints. The thing is, with multiple cars, I need to slow them / stop them when there are more cars waiting (simulating high trafic) like this: https://gyazo.com/32fee445fde6a266e95c46a561616a7d (here it is working because I can do the calculation at the start of the instance of every car, setting a different path with less waypoins if there are cars in the road)

    What about not changuing the waypoints positions, but slowing down / stop / move the object to another waypoint, all during runtime?

    If you think I will have the same restriction as in DOTween and it is a code thing, and your asset won't help me, thank you anyway for your response!
     
  11. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Our movement scripts have a method for changing the speed, but that is simply a wrapper for DOTweens tween.timeScale variable, where you are able to change its speed over time e.g. by setting it in a coroutine.

    So no, if you already have the most of this working with DOTween already and don't need the visual part, then getting SWS would not be beneficial.
     
  12. DevilDarkSlayer

    DevilDarkSlayer

    Joined:
    Oct 11, 2017
    Posts:
    6
    It works!!!!
    Thank you so much :)
     
  13. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Hello @Baroni,

    any chance of helping with a Playmaker action modification? It's the Add Event At Waypoint action:



    It's a neat action, but you can't add the event if the object you want to send the event to is not in the scene.

    I tried combining it with Playmakers' Send Event action but i'm afraid my skills in these matters are not on par.



    Is it possible to send the playmaker event, it's much more useful, it uses fsm.event(eventTarget, sendEvent).
     
  14. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi @Kruko, the action has been a regular event in the past, but was requested to change to what it is now. I'm not that familiar with PlayMaker, so while I try to maintain the actions included, it's not something I am actively developing or prodiving support for. Maybe other users can help tho - feel free to share the action code on the PlayMaker forums.

    How would that even be possible in Unity's current workflow? :confused: Since the "object" should be the object with a movement script, wouldn't it be easier to just instantiate it and send the event afterwards?
     
  15. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    @Baroni

    Yeah i'm aware of that, what i meant is for the object to send an event to the reference, but i cant figure out how i can choose the fsm receiver on runtime.

    I made a workaround solution, i have a spawner object which is always in the scene and saves the spawned ships references so they can send the event to the spawner upon reaching waypoint which, in return, sends the appropriate playmaker event to them.
     
  16. kikoukop

    kikoukop

    Joined:
    Dec 29, 2011
    Posts:
    16
    Hello, I am a user of your Simple Waypoint System kit and I have been using it to move all kinds of objects.
    Now I need to use it with a human character walking on an inclined terrain, but this inclines to adjust at all times to the perpendicular to the ground and it does not seem very realistic, is there any way that the character retains the vertical during his career?
     
  17. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi @kikoukop, with splineMove you can let an object rotate following the path direction, which is what the "pathMode" dropdown is for. A tween does not automatically "adjust" to environment around it, like terrain. It is bound to the path you've created and does not do any ground detection. If you would like to add a custom rotation, you could either try the experimental waypoint rotation feature (see the separate example scene for that), or attach your own custom script to the object which contains a LateUpdate method. In that method, you would overwrite the tween's rotation calculation with your own ground detection behavior.

    If you are actually using navMove, then you would need to overwrite the NavMeshAgent calculation instead.
     
  18. kikoukop

    kikoukop

    Joined:
    Dec 29, 2011
    Posts:
    16
    Thanks Baroni, your information has been of great help to me!
     
  19. Mark-Ripley

    Mark-Ripley

    Joined:
    Aug 22, 2007
    Posts:
    148
    Hi,

    We've had a strange problem appear when upgrading Unity to 2017.2.0 from 5.6. If I press play in the editor and navigate to the scene containing the paths, the yellow waypoints path seems fine, but the generated white paths are corrupt, containing spurious wild values. A picture will explain better:



    I've upgraded the plugin to the latest one (5.4.1 - Sept 8th '17), but the problem persists. I did notice that when I imported the unitypackage, the "out of data APIs" warning dialog appeared.

    Any clues?

    Many thanks :)

    M
     
  20. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi @Mark-Ripley,

    I haven't seen that before. Which 2017.2.0 version did you use? There's a bug in 2017.2.0f3 regarding waypoint placement (mouse position being off) which was only fixed in 2017.2.0p2 onwards. Doesn't look like that's the issue here though.
     
  21. Mark-Ripley

    Mark-Ripley

    Joined:
    Aug 22, 2007
    Posts:
    148
    Yes it is f3 - I'll try p2 and see if it helps :)
     
  22. Mark-Ripley

    Mark-Ripley

    Joined:
    Aug 22, 2007
    Posts:
    148
    Installed 2017.2.0p4 (I was feeling brave) and it did the trick! All fixed, thanks :)
     
    Baroni likes this.
  23. m0ds84

    m0ds84

    Joined:
    May 25, 2016
    Posts:
    18
    Hi there, is there a particularly good setting/option for things like vehicles? For the most part, a standard path is pretty good. But hitting some of the waypoints can spin the vehicle un-naturally, and of course, there is no natural "bounce" due to terrain collision detection or anything. But maybe someone found some settings that improve the realism for vehicles? I'm fairly new to this asset so haven't gone too in depth to other settings, but it's working nicely. Thanks!
     
  24. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi @m0ds84, since tweens are fixed animations, they keep objects right on the actual path, with no forces applied from the environment. Bezier paths give more control in fine tuning the curves, but this also takes more time to set up. What you could do, is to write your own script that does some ground detection on top of the movement script and applies the rotation on your moving object, e.g. by taking its current speed into account.
    Regarding the spinning, try using the "Lock Rotation" dropdown in the inspector to prevent unnatural axis rotations.
     
  25. MMccathron

    MMccathron

    Joined:
    Feb 27, 2015
    Posts:
    13
    I am interested in your system, can it be used at runtime in a game environment? For instance plotting the path of soldiers during the game in a real time tactical game?
     
  26. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi @MMccathron, SWS allows to instantiate predefined paths during runtime, and our web player has a sample scene for that you can have a look at (it should be labelled "runtime"). Additionally, you can also calculate and construct a new path at runtime, by placing waypoints yourself.

    What SWS doesn't allow is to modify existing movement tweens (already running movement) at runtime, since that is not how tweens work and would require stopping and starting the movement tween again to take the waypoint changes into account. You're a bit more flexible when using navMove (our movement script for Unity's navigation system), since you can also do waypoint changes for NavMesh agents while they move, so they continue from their current position.
     
  27. pre111

    pre111

    Joined:
    Dec 11, 2017
    Posts:
    3
    Hello Sir

    I purchased your asset about 4 months ago and due to being hit buy a drunk driver while riding my motorcycle am now just getting around to playing with your asset. It is very easy to use and that alone makes it a very cool asset. One question though if I shoot my enemy and my enemy ragdolls how do I stop that ragdoll from continuing to move along the path I created once the bad guy is dead? Please note I am not very smart when it comes to coding but at this point kind of understand unity in other words if you can keep your answer easy to understand I would thank you for that....
     
  28. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi @pre111, hope you're well now.

    To stop the movement script, just get a reference to it and call its Stop() method. Please find all public methods in our scripting reference.
     
  29. pre111

    pre111

    Joined:
    Dec 11, 2017
    Posts:
    3

    I really do not mean to bother you but is there any way you can show me an example as I have no idea what you are talking about. Again I am really sorry to bother you again...
     
  30. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    @pre111 I'm not going into detail on how to call methods of scripts in Unity, as that's pretty much Unity beginner coding 101: https://unity3d.com/de/learn/tutorials/topics/scripting/getcomponent

    But our runtime example scene has a sample on calling all methods too. Open "Example7_Runtime" scene and have a look at its "RuntimeDemo" script.

    Code (csharp):
    1. splineMove move = targetGobj.GetComponent<splineMove>();
    2. move.Stop();
     
  31. pre111

    pre111

    Joined:
    Dec 11, 2017
    Posts:
    3

    That is all I needed Thank You very much you have been a huge help
     
  32. Ahmad_Nauman1

    Ahmad_Nauman1

    Joined:
    Nov 17, 2017
    Posts:
    3
    Can I make waypoints on runtime by drag or click? any solution or script for help?
     
  33. Ahmad_Nauman1

    Ahmad_Nauman1

    Joined:
    Nov 17, 2017
    Posts:
    3
    I want to make waypoints on Runtime by drag or click? any script or anything?
     
  34. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    @Ahmad_Nauman1 Waypoints are just regular game objects. You would need to write your own point&click script for creating game objects at runtime, then attach a PathManager component to a game object in the scene and link your newly created waypoints in its "waypoints" array.
     
    Ahmad_Nauman1 likes this.
  35. Ahmad_Nauman1

    Ahmad_Nauman1

    Joined:
    Nov 17, 2017
    Posts:
    3
    I was looking for some script for some help. Thanks! Anyway.
     
  36. Infantry

    Infantry

    Joined:
    Nov 22, 2017
    Posts:
    7
    Quick question,

    How do we attach an FPS prefab to the camera movement so it uses the original features of the FPS PREFAB and does not remove any of the featured. Id like the prefab to move on the ground with footsteps and keep all of my prefab effects (Tracer, EXC).

    Thanks,
    Brad
     
  37. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi Brad @Infantry,

    I'm not sure which FPS prefab you mean, or what SWS has to do with foot steps? You can't have two controllers (a tween running and controlling position) and a character controller or rigidbody on the same object, both fighting for control of the object.
     
  38. Infantry

    Infantry

    Joined:
    Nov 22, 2017
    Posts:
    7
  39. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    @Infantry I don't own that asset. You can have a tween running on a child of a game object (locally, e.g. for camera movement around a car or for animating cameras between 1st and 3rd person), or pause the tween on player input, at any time, and let some other script take over (e.g. for jumping - or vice versa). But not both at the same time, on the same game object.
     
  40. Infantry

    Infantry

    Joined:
    Nov 22, 2017
    Posts:
    7
    Thanks will figure it out gave you 5 stars for great setup and quick reply!
     
    Baroni likes this.
  41. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    To all Unity 5.x and 2017.x users:

    with Unity splitting their development streams into TECH and LTS (read more about that here), we will also upgrade our standard Unity version to the first LTS release - Unity 2017.4.0. Unity 5.6 is about a year old, and out of official support, so it is time to move on. I've just uploaded a 2017.4.0 version of this asset, and will remove all older Unity compatible asset versions in 2-3 months from now. Also, new updates to our assets will only be made to active LTS version(s).

    What this means, in short:
    - we're stopping support for Unity 5.x soon
    - Unity 2017.4.0 will be the minimum required Unity version at that point
    - we're going to support our assets for each Unity LTS version over its full lifetime (2 years)
     
    tosiabunio likes this.
  42. KIR99

    KIR99

    Joined:
    Feb 21, 2017
    Posts:
    19

    Ran into this issue yesterday, it didn't set path because Waypoint Manager wasn't assigned.
    What i did to fix this was at the start of Void OnSceneGUI() just reassign it with:
    if (script == null)
    {
    //get manager reference
    script = (WaypointManager)target;
    }

    worked for me.
     
  43. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    Is this fully compatible with Unity 2018.1? Can this be used to move any object without the use of Navmesh like for flying/swimming?
     
  44. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Yes, but let me know if you run into any issues.

    That's what the splineMove script is for, using DOTween (the tweeting library) to animate objects. Note that tweens are fixed movements along a predefined path.
     
  45. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    Do I still require DOTween to make the splineMove script work? I'm wondering, what's the main feature differences between Simple Waypoint System and DOTween with regards to moving objects?
     
  46. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Yes, the free version of DOTween is sufficient and already included in SWS. DOTween is more focused on tweening values of any type, while SWS focuses completely on editor path creation tools, path controls and different movement settings. There are movement controls in SWS which do not exist in DOTween.
     
  47. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    I guess Simple Waypoint System is like extending the functionalities of DOTween by making it more easier to create paths and fine tune movements. Can you specify some of those movement controls that are only in SWS?
     
  48. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    The free version of DOTween only has programmatic access to very simple path tweens (pass in Vector3 array and let an object move along that), so there's nothing to compare, really :)

    Is there anything specific you are looking for?
     
  49. RendCycle

    RendCycle

    Joined:
    Apr 24, 2016
    Posts:
    330
    I'm actually confused between the two and looking for the most ideal tool I can use since I can only get one at the moment. Right now my requirements is just to be able to move objects easily. The objects would be several equipment/parts of a vehicle (e.g. crane, net, spotlights, etc.) and the second one would be for swimming/flying creature movements. Later on, I would also probably need something for UI animations/movements.

    By the way, how does the Random movement feature work? Will the object move randomly on any of the waypoints created so there is no order?
     
  50. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    @RendCycle
    Well, the free version of DOTween is... free. You can download it right now and test it out, if you are "average" at programming and understand its API. If you need a visual tool that gets you started with paths and movement object / path management, then SWS would be a better choice.
    Again, DOTween is free, DOTween Pro is the same price as SWS and focuses on animating everything that has values, basically.

    "Random" puts all waypoints in a random order for your object to move through, before starting movement. It randomizes the order at every loop again. That's one of the settings specific to SWS only.
     
    RendCycle likes this.