Search Unity

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,260
    You can move the whole path, but you cannot move/add/delete individual waypoints (while moving on the path).
     
  2. Meceka

    Meceka

    Joined:
    Dec 23, 2013
    Posts:
    423
    Hello, I have made a car follow a path, then I want it to park in reverse after some time. I tried to make it stop rotating on a waypoint, then it will go straight in backwards direction, and I thought, with changing path mode from "full 3d" to "ignore" will make it stop rotating, and It will just go backwards. But chaning path mode works after path ends and animation loops from the beginning. I want it to stop rotating the car immediately on a waypoint, how can I do that?

    If you have another idea to mimic a reversing car, please share. I need same behavior for a "car ferry" moving reverse from an harbor, and than following the path with looking on path's rotation)

    Thanks
     
  3. louis_k

    louis_k

    Joined:
    Mar 10, 2015
    Posts:
    3
    Hello Sir,

    Sorry for the delay

    I applied it, it works fine and it is super easy ! (Now I think I am idiot for spending a lot of time on this :p)

    Thanks again
     
    Baroni likes this.
  4. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Hi Meceka,
    you could use two different paths for the forward/backward movement and change the settings on the movement script via code inbetween. At the end of one path, just switch to the other one.
    You can also overwrite the object rotation manually in LateUpdate, if you wish to. This is being done in the Example6_PathInput scene, when the character should move left - there we add +180° to reverse its orientation.
     
  5. MIK3K

    MIK3K

    Joined:
    Sep 10, 2014
    Posts:
    144
    Hi, just started using this in Unity 5 with great success last night, but I loaded up the same project and now I am getting 2 errors -

    Assets/SWS/Examples/Scripts/PathInputDemo.cs(65,24): error CS1061: Type `DG.Tweening.Tweener' does not contain a definition for `fullPosition' and no extension method `fullPosition' of type `DG.Tweening.Tweener' could be found (are you missing a using directive or an assembly reference?)

    The second error is the same but for PathInputDemo.cs(56,24)

    I'm new to scripting so not sure how to fix this. I tried deleting the PathInputDemo.cs but that introduced new errors. Maybe I'm missing a file somewhere?
     
  6. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Hi there, did you modify the PathInputDemo.cs file somehow or accidentally deleted/moved the SWS > Plugins > DOTween folder?
     
  7. MIK3K

    MIK3K

    Joined:
    Sep 10, 2014
    Posts:
    144
    I don't remember touching PathInputDemo.cs, but I did install the full version of DOTween. Wonder if that is what caused this. I have to go to work right now, but I'll check it tomorrow. I'm pretty sure 99.9% of errors I get are self-inflicted but thought maybe you heard of something similar. Thanks - This gives me something to look into.

    ---------------

    Took a few minutes out of work to look at this. Ended up downloading the latest version of DOTween from the devs website (through the handy editor window) and it recognized Unity 5 (maybe the other version was still Unity 4.x?), deleting the old and installing the new "Dotween" folder inside the "assets > demigiant" folder. It all works perfectly again. SWS is wonderful once again!
     
    Last edited: Mar 17, 2015
  8. Julian-S

    Julian-S

    Joined:
    May 31, 2013
    Posts:
    73
    Hello,

    I am wondering is it possible to move the waypoints during runtime? I need to have characters moving on a moving platform (a ship).

    Thanks!
     
  9. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Hi Julian, you can move whole paths with their characters at runtime. It is not possible to reposition individual waypoints while an object moves on them though.
     
  10. MornFall

    MornFall

    Joined:
    Jan 11, 2013
    Posts:
    160
    Hi Baroni,

    I just bought and tried this system : Works very well, very VERY easy to setup. I was about to start making my own WP system when i saw your plugin. those 15 $ probably saved me a few weeks.

    Although, i have a question. I quickly went through the doc and the forum but i did not see anything to answer my following question :
    I need my moving units to rotate depending on the normal they are walking on.
    Think of it as spiders, walking on walls / ceilings, ect ...
    Before i try to make my own "splinemove" script, is there an easy way to do that, with the scripts you provide ?
     
  11. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Hey Feydwin, thank you for your purchase.

    Regarding rotation, you have the option between rotating your object to the path (Path Mode: Full3D) or no rotation at all (Path Mode: Ignore). A possible solution for manual rotation could be to disable the path rotation, thus selecting Path Mode Ignore, and writing your own script that only modifies the object's rotation. This way you don't have to write your own movement script.
     
  12. MornFall

    MornFall

    Joined:
    Jan 11, 2013
    Posts:
    160
    Answer in less than 5 minutes. Love that.
    Alright then, Ignore path Mode + raycast to get the ground normal on.
    I think i will still make my kind of own splinemove script, so it only uses what i need, and integrate that normal follow in it.

    Thanks !
     
    Baroni likes this.
  13. MornFall

    MornFall

    Joined:
    Jan 11, 2013
    Posts:
    160
    I am pulling my hair on that one....
    Something that i am sure is pretty simple but i don't get it.

    When i try :
    private splineMove move ;
    move = GetComponent<splineMove>() ;

    I get a stubborn error :
    "...The type or namespace name `splineMove' could not be found..."

    Even if i am using that very specific splineMove script to move this object ...

    Help ?


    EDIT : Nevermind .. was just being stupid... Did not see the namespace at the top of splineMove...

    EDIT 2 : Actually, still running into one issue...
    I made my MoveItem.cs , which is a copy/paste of splineMove, but without the nameSpace SWS, i instead put using SWS. That makes my object moves just fine.
    But...
    I want to assign the path after i instantiate the prefab... So when i try :
    move.SetPath(WaypointManager.Paths["Path01"]) ;

    I get a :
    "The name `WaypointManager' does not exist in the current context"

    So, what is the easy way to assign a Path to a prefab that i just instantiated ?
     
    Last edited: Mar 18, 2015
  14. s1m0n1stv4n

    s1m0n1stv4n

    Joined:
    Sep 14, 2012
    Posts:
    16
    Hi @Baroni ,

    I have a path above a 2d side scroller terrain, across the whole length of the level.

    I'd like to know the position that is on the path and has a specific x coordinate i.e. the point on the curve that is exactly above a certain object. Is there any way to do this?
     
    Last edited: Mar 24, 2015
  15. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @Feydwin
    Sorry, didn't see your second edit. Theoretically it should find the WaypointManager when using "using SWS". Did you try to use SWS.WaypointManager.Paths too?

    Hi there,
    I'm not aware of a method in DOTween (which stores the paths) doing this, nor is there a "nearest point on path" method available. A possible solution could be to use an invisible object that moves on the path to find the position you are looking for. tween.Goto(time value) sends your object to a specific time on the path. You could use this in a loop to find the nearest point in approximation, where the x position of the invisible object matches to the x position of your object. At that point, read out the position of the invisible object on the path. Also try asking the developer of DOTween directly for an alternative solution.
     
  16. s1m0n1stv4n

    s1m0n1stv4n

    Joined:
    Sep 14, 2012
    Posts:
    16
    I feel that is a bit overkill :) But thank you for answering me so quick. I'll take a shot at the DOTween forum. Thanks again!
     
  17. yahodahan

    yahodahan

    Joined:
    Apr 26, 2009
    Posts:
    1,380
    Great tool, 2 notes:

    1) Bug: if you place an object exactly at the starting node of a path, with "move to path" enabled, then assign it that path, it will glitch. Specifically, when it reaches the second waypoint, it will double back to the first waypoint. If you move the object just a fraction off the starting node, this does not happen.

    2) Is there a way to control Roll along the path? I have an aircraft moving along the path, and would like it to roll as it turns, amount of roll dependent on the sharpness of the turn.

    Thanks, extremely useful right away!
     
  18. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Hi Gabriel, thank you very much for using it!

    I'm thinking about automatically deactivating "move to path" if the object already starts at the first waypoint, would that be a feasible fix for you?

    There's a bit of scripting involved in this one. You could use a "leading object" moving in front of your aircraft, to calculate the direction changes a few steps ahead. Then with the sharpness of the turn (direction Vector) given, update the rotation of the aircraft accordingly. This question comes up from time to time, maybe I should include a demo at a later point... thanks for the feedback!
     
  19. tomi-trescak

    tomi-trescak

    Joined:
    Jul 31, 2013
    Posts:
    78
    Hello! Good work on the asset! Been using it for some time, but recently I have started to use it with navmesh agents and immediately ran into problems, when on paths, which are on more complex terrains, agents would never moe to next waypoint. Localised error to following code:

    Code (CSharp):
    1. //wait until the agent reached its destination
    2.         private IEnumerator WaitForDestination()
    3.         {
    4.             while (agent.pathPending)
    5.                 yield return null;
    6.  
    7.             float remain = agent.remainingDistance;
    8.             while (
    9.                 remain == Mathf.Infinity ||
    10.                 remain - agent.stoppingDistance > float.Epsilon
    11.                 // || agent.pathStatus != NavMeshPathStatus.PathComplete // TOMI: this is never true - getting path partial even when at destination
    12.                 )
    13.             {
    14.                 remain = agent.remainingDistance;
    15.                 yield return null;
    16.             }
    17.         }
     
  20. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Hi tomi,
    is the stopping distance on the agent set to something greater than 0? 0.5 works best in most cases.
     
  21. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    This asset is currently included in the Asset Store MADNESS sale! Get it 65% off for a limited amount of time:

     
  22. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    346
    Got it! Damn this is really well done! Exactly what I was searching for, and with playmaker support!

    I have a question regarding speed. It seems the playmaker action "SWS_Change Speed" does not work correctly or I use it the wrong way: the speed can only set once the action is called, the checkbox "every frame" does not work!

    What I would like to do is to control a mecanim character with attached camera, but the character should accelerate and deccelerate instead of start / stop without any smooth transition. Is this possible? Something like in "Example8_RapidInput", there the speed is set every frame with "RapidInputDemo" script.

    SWS is great, hope it is possible to make smooth speed transitions on my path :)
     
    Last edited: May 7, 2015
  23. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Thanks! Did you check the PlayMaker sample scene that comes with SWS? I can't see any issues with resetting to the first waypoint on a speed change there. There's a small error in the SWS_ChangeSpeed script though, I think Finish() should not be in that script.

    Acceleration and decceleration should be handled by using PlayMaker actions and variables, and then passing them over to the ChangeSpeed action that runs in a loop.
     
  24. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    346
    Thanks Baroni, did not notice that there is a playmaker expample scene :)

    I modified SWS_ChangeSpeed action, now it works like expected (if every frame option is checked you can set the speed per frame).
     

    Attached Files:

  25. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    346
    WaypointManager does not work with the latest Unity 5.1.0b5.
    (path name can not be typed in => unpossible to create path; pressing P inside viewport has no effect, no error messages)

    Do you have any idea how I could get it to work with the latest beta version (conditionally I need the lastest beta)?
     
  26. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Unfortunately I have no clue what changed there (and have no resources to support beta versions), but you could submit a bug report if it actually does work under the same circumstances in an older Unity version.
     
  27. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    @Baroni , I was looking at your plugin as a possible solution for making my camera more dynamic. I was wondering when you mention Camera animations and cutscenes as part of your plugin, what does that include exactly?
     
  28. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Good question! Besides creating your paths in the editor and fine-tuning them with bezier curves or the like, you'll have actions to change the movement speed and add custom events at waypoints, such as playing another animation or calling own methods. These things help working in the editor without writing code. Of course you still have access to the underlying DOTween implementation and can fast-forward or rewind the tween of your objects directly.
     
  29. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    Am I able to access camera data such as the field of view and the camera's rotation on the paths in the editor? Or would that require custom events?
     
  30. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    No, not directly. You would set up a waypoint event with some data (int,floats,etc) in the inspector, that calls your own method and adjusts these things at runtime.
     
  31. wana7262

    wana7262

    Joined:
    Jul 2, 2012
    Posts:
    103
    on switching the path, the AI Player moves to the first node of the next path, is it possible to move the player to the current node or +1 node of the switched path?
     
  32. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Yes, modify the "startingPoint" variable on the movement script.
     
  33. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    Can I create paths or modify it's nodes position in code so I can have different paths in runtime, depending of the game situation?

    Thanks in advance
     
  34. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Hi,

    waypoints are just gameobjects in the world so yes, you can create or modify their position at runtime. If you have moving objects on the path while modifying them, the moving object won't update its path positions until the next loop (or until you stop/restart it). This is due to the nature of tweens, which are just like pre-defined animations. An exception to this is the NavMesh movement script, which will also consider current waypoint updates.
     
  35. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    Since I'm making a board game it seems like an elegant solution to move an "origin" and "target" gameobjects depending on the die value and current position of the player and then animate the player gameobject following the path between them.

    Thanks for the quick reply.
     
    Baroni likes this.
  36. FisherM

    FisherM

    Joined:
    Dec 28, 2013
    Posts:
    366
    What is the performance like? how many can you get going?
     
  37. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Unity NavMesh agents: hundreds, DOTween tweens: thousands.

    *limited by your renderers and game logic updates
     
  38. JohnRossitter

    JohnRossitter

    Joined:
    Dec 18, 2013
    Posts:
    1,027
    Hi, I have had SWS for over a year but just now started to use navMove with it.
    It's a great feature, but I have a question. I have an AI situation where I want my NPCs to patrol the navmesh during gameplay, but certain events would trigger them to use traditional navmeshagent movement. I am able to stop the navMove control by calling navMove.Stop(). But once my event is over, i cannot re-enable the navMove movement by calling navMove.Resume().

    What is the best way to have the NPCs resume navMove once it has been stopped ?
     
  39. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Hi, if you want to resume it later you would call Pause(), not Stop().
     
  40. JohnRossitter

    JohnRossitter

    Joined:
    Dec 18, 2013
    Posts:
    1,027
    Ok, so should I just set the timeout to something like 1,000,000 ?
    Since I dont know how long it will be paused.
     
  41. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Naah, just pass in 0 (or nothing, it's an optional parameter) and it will paused until you resume it manually :)
     
  42. JohnRossitter

    JohnRossitter

    Joined:
    Dec 18, 2013
    Posts:
    1,027
    There you go, works like a champ!
     
    Baroni likes this.
  43. Infectedcell

    Infectedcell

    Joined:
    Jan 23, 2015
    Posts:
    24
    Hi!

    Got it yesterday evening and its awesome (first look)

    One little question (did not try yet by myself):

    I have an Enemy which is hunting / chase main character (using Navmesh)
    Is that possible to use SWS waypoints ( as represented in Navmesh example) to allow Enemy chase my character within Navmesh system (or without it) BUT using SWS waypoints (from point to point - chasing character)?

    Not (wp1, wp2, wp3 etc. but randomly - from wp to another wp - which is apart to my character)

    Or which script (from SWS) I need to use to realize it?

    I have try to use Events within Example3 (Navmesh) - .."SetDestination" for navmesh agent "Eten" to Gameobject "sphere" - So, Eten leaves SWS and start run to different sides but not to destination gameobject..

    Also tried to write my own event fuction to set destination to navmesh agent (my character as target) - also does not work at all =(

    Just wish to navmesh agent follow my character but not leaves waypoints from SWS
    How to achieve it? Is that possible with SWS?

    Thanx!
     
    Last edited: May 13, 2015
  44. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @Infectedcell
    Hi, I'm not exactly sure how you want to do both things at the same time (chase+follow path)? I can imagine some sort of logic as seen in pacman, but you wouldn't use a waypoint system for that. A path has a fixed start and end point and an order of waypoints. What you're after wouldn't be the best fit for a waypoint system. I guess you would have to detect which path or waypoints your enemy has to use to ultimately get to the player, and that's not something SWS can do for you (out of the box).

    If you would like to take control over the agent to do something else, you have to call Stop() or Pause() on the navMove script first.
     
  45. Infectedcell

    Infectedcell

    Joined:
    Jan 23, 2015
    Posts:
    24
    @Baroni

    Imagine that you are developing side scrolling platformer - like Deadlight - where you move only in Z axis (left to right / right to left)

    1. So, you have a few waypoints located on area - along Z axis (with fixed X,Y positions)
    2. Your character moving along Z axis (left to right / right to left)
    3. Enemy which is located somewhere on level - spotting your character and then pick closest waypoint (to your character) and start moving to selected waypoint from any directions (something called "Move to path" in SWS).
    4. Then enemy reached to this waypoint it starts moving ONLY along waypoints located on level area (see p.1) - to one side or to another - depending where your character is - but not as free navmeshagent but as linked to waypoints)

    Default Navmesh agent solution does not work this way.

    I suposed to use NMA as solution for targeting enemies and SWS as waypoint system
    I still think - it is possible to realize and your suggestions would be highly appreciated.

    The best example I saw is the Deadlight game:

    Enemies located on different X (depth - closer / ), Z position - when enemy spotted character - it start moving to closest waypoint (or predefined waypoints and then - only in Z axis.

    Something like this.
     
  46. Infectedcell

    Infectedcell

    Joined:
    Jan 23, 2015
    Posts:
    24
    Thanx! it works!
     
  47. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Thanks for the explanation, I get it now! This could be very simple indeed. If your enemy spots the character, you could create a path at runtime. E.g. one waypoint at the character position, one waypoint at the end of the level (left/right). Then assign this path to the enemy and let it follow the path, so it looks like it is chasing the player to the end of the level.

    Runtime path creation in more detail:
    - create empty gameobjects as waypoints and store them in an array, in the order you want them to be
    - create another empty gameobject as the path parent and attach the PathManager script to it
    - assign the waypoints to PathManagers "waypoints" array
     
  48. Infectedcell

    Infectedcell

    Joined:
    Jan 23, 2015
    Posts:
    24
    Thank you! =) Looks like this solution should work as needed. I should try it.
     
  49. Hamad08

    Hamad08

    Joined:
    May 14, 2015
    Posts:
    9
    i bought ur plugin pretty impressive overall... im trying to set my player as a waypoint of the enemy so that it follows it... is it possible??
     
  50. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @Hamad08 thanks! Could you make an example of how that would work? If you just want your enemy to follow the player, that wouldn't be the job for a tweening system. If something has to update every frame, the Update() method should be used.