Search Unity

Simple Waypoint System (SWS) - Move objects along paths

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

  1. Spookyy2

    Spookyy2

    Joined:
    Oct 10, 2016
    Posts:
    2
    Restarted clean and reset the InputManager seems to have fixed it. So all OK now.

    ...

    Restarted Unity after testing SWS awhile and now it's broken again. Reset do not fix it this time.
    ...

    Something fishy here, deleted all my projects and restarted and now it kicks in again.... and borked again.
     
    Last edited: Oct 13, 2016
  2. txarly

    txarly

    Joined:
    Apr 27, 2016
    Posts:
    197
    hello,

    Can SWS integrate with Realistic fps (RFPS) as this uses waypoints to move the AI?

    Thank you
     
  3. Baroni

    Baroni

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

    I do not own Realistic FPS so I can not tell for sure, sorry. If it has a separate script for moving AI which does nothing else and has no other variables, it could be replaced by SWS, otherwise you will have to do some code changes.
     
  4. IgorAherne

    IgorAherne

    Joined:
    May 15, 2013
    Posts:
    393
    Baroni, I beg you m8, please make a nearest-point function for Bezier!! xD We really need it.

    When working with the BezierPathManager, I know my wp index, so can I get all those small points which connect "main waypoints"? For example, bezier curve could have around 50 "main waypoints", and like 400 small ones. I am interested if given "main waypoint number 12" I could find out that it corresponds to, say, small points between indices 150 - 170 etc.
     
    Last edited: Oct 22, 2016
  5. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    @IgorAherne a "closest point" method is on the roadmap, no ETA though. Sorry, asset support takes a lot of time lately but new features are being worked on from time to time.

    Usually each segment (waypoint to waypoint) has 10 smaller waypoints, when using the default segment detail of 1. That means waypoint 12 would be between 110 and 120 small points (pathPoints array on the BezierPathManager).

    On the same matter, getting the closest waypoint would be simple i.e. just iterating over all of them and doing a distance check. Finding the nearest smaller point on a segment could be achieved similar to that (while not that optimized), by iterating over the pathPoints array. But there is more mathematics involved as you would have to find the percentage on the path of that point, then set the tween's fullPosition time value to the tween's Duration * percentage, given you don't apply any easing (where the path percentage would not relate to the position anymore).
     
  6. RF008

    RF008

    Joined:
    Oct 28, 2016
    Posts:
    20
    Hi
    i am using navmove to move a object when i want to reverse the object it is not going reverse instead it is taking some random point in the path.
    i need this to be working soon.
    pls give me workaround.
     
  7. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi @RF008, your description is too vague. Could you please provide code snippets you are using or repro steps in one of the sample scenes. Also, which version of SWS are you using.
     
  8. Ravl

    Ravl

    Joined:
    May 14, 2013
    Posts:
    35
    @Baroni
    When my object start the path is automatically rotated 180 degrees. I assume this is happening because the object 'forward' vector is also + 90 degrees

    Anyway, I tried to block rotation on Y, but is not working.. It even rotatate my object on X axis too
     
  9. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    @Ravl "Locking" a rotation means that it stays at the initial value set by DOTween while moving on the path. This is not what you want.

    The object being rotated to a different direction is because of the original rotation of your model as you've expected. You can either 1) go back to your modelling application and apply the correct rotation or 2) create a new parent gameobject for the object, have the movement script on the parent and rotate the child (the model) by 180 degrees.
     
  10. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Hi Baroni,
    that example seems to be broken. The ball stays at the first waypoint of the rotating path but doesn't move along.
    Using SWS 5.2 on Unity 5.4.0p1. Any ideas what went wrong?
     
  11. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi @Marco-Sperling, thanks for catching that. Could you check the 'Ease Type' variable in the movement script inspector, and if it's set to 'Unset', change it to 'Linear' instead.
     
    Marco-Sperling likes this.
  12. RF008

    RF008

    Joined:
    Oct 28, 2016
    Posts:
    20
    i Am using nav mesh move i am calling reverse function but some times it does not work and i am using latest version of the sws.
     
  13. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    @RF008 sometimes? I made a UI button for testing that calls .Reverse() on a navMove component. I couldn't find any issues with it, it even worked with loops as expected. Could you please share repro steps or a minimal project via email as I said in my last post to you.
     
  14. K1kk0z90_Unity

    K1kk0z90_Unity

    Joined:
    Jun 2, 2013
    Posts:
    90
    Hi,
    I would like to be able to add new waypoints at runtime to a PathManager, and have the splineMove object following that path to be notified of the path change, so that it keeps following the modified path without restarting from the beginning. Is it already possible out-of-the-box or should I modify your scripts?
    Thank you in advance for your answer! :)
    BTW, really great package!
     
  15. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi @K1kk0z90_Unity, modifying the path while letting an object walk on it is not possible due to the way tweens work. They are fixed - like animations, and need to reinitialize when something changes. You could modify the path at a waypoint though, and send the object back to the waypoint (via GoToWaypoint method) after adjusting the path.
     
  16. James-Williams

    James-Williams

    Joined:
    Aug 30, 2016
    Posts:
    26
    can you post a link to this please.
     
  17. James-Williams

    James-Williams

    Joined:
    Aug 30, 2016
    Posts:
    26
    I have a waypoint path setup and the player can move freely in small area. Once the player reaches a Trigger my script accesses the SplineMove script attached to the player and calls splineMove.StartMove() function on key press and sets the path from an array of paths. The player moves to the path and goes about its way from point A to point B.

    The issue is that once a path is chosen and the player leaves point A if I press the button to change paths, I want the player to proceed to point B of the chosen path and not go back to point A of the chosen path.

    Not sure how to implement this.

    Also I have tried moving the 1st point to my location on button press but that makes the player move to the points origin so that doesn't work either.

    here is my quick code for testing.

    Code (CSharp):
    1. if(Input.GetKeyDown(KeyCode.P))
    2.         {
    3.             index = Random.Range(0, pManagers.Length);
    4.             sMove.SetPath(pManagers[index]);
    5.             sMove.moveToPath = true;
    6.             sMove.StartMove();
    7.  
    8.             Debug.Log("Moving to path");
    9.         }
     
  18. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Hey,
    got a question concerning the animator controller you used in your numerous examples for characters walking along paths:
    Is there anything special about it?
    I tried to clone its setup (idle, walk, run with their respective transitions [idle->walk, idle<-walk], [walk->run, walk<-run]) but my character only starts walking at the third or so waypoint. Before that it keeps playing its idle animation.
    Also is there a way to control the character speed to make it run midway and slow down to a walk near the end?
     
  19. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Here is a thread that describes the process of runtime path creation.
    https://www.rebound-games.com/forum/index.php?topic=55.0

    There are multiple issues with your code. First, you set the moveToPath variable after setting the path. Second, you call StartMove() two times because SetPath does this already. To start on a waypoint in the middle of another path, use the startPoint variable.

    Code (csharp):
    1. splineMoveScript.startPoint = ...;
    2. splineMoveScript.moveToPath = true;
    3. splineMoveScript.SetPath(another path);
    Hi, did you check the required transition speed between animation clips in the Animator window? It could be that your speed is just too slow to change between animation states.

    You could use events at waypoints for changing the speed, a coroutine that calls ChangeSpeed on the movement script over time, or a different ease type.
     
  20. Hazneliel

    Hazneliel

    Joined:
    Nov 14, 2013
    Posts:
    305
    Hey, just FYI, I did some stress testing on a not powerful mac. I was profiling SWS vs Population System and I found that SWS performs better! =)

    I setup 3 paths, then I added 100 humanoid walkers to the scene. I also added some obstacles and made the walkers use the NavMesh. With population system I setup the same.

    SWS is performing better because its not doing physics calculations as Population system does. I attach some screenshots of the profiler, its a little hard to see because of the spike but you can see left of the spike the performance of SWS and right of the spike the performance of Population System.

    The only good thing of Population system is that it only took 5 minutes to setup, versus SWS that takes a lot longer to setup but the performance for me its worth it.



    SWS Left of the Spike
    Population System Right of the Spike.
     
    Baroni likes this.
  21. cryogee

    cryogee

    Joined:
    Aug 6, 2009
    Posts:
    132
    Hi,

    How to programmatically setup bezier curves or circular path?

    I dont want to set paths manually in editor.

    Any examples will be appreciated.
     
  22. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi @cryogee, please see the link in this post above. Creating waypoints for a BezierPathManager works the same, but there you have to create BezierPoints and assign them to the bPoints list. Calling CalculatePath will regenerate the bezier path at runtime.
     
  23. Milox_

    Milox_

    Joined:
    Nov 25, 2016
    Posts:
    2
    Hi !
    A little question: I have a set of "GameObject" defining a way like this example:
    X Y Z
    0 1 0
    5 1 0
    7 1 3
    6 2 8

    Is there a way to "import" or "convert" this set of points with their x,y,z coordinates into a SWS path ? I have 1000+ points, so, I'm looking a way to avoid manual one-by-one point enter. Alternately, can I manually edit a SWS path with an external editor, in example, a text editor? I could "generate" all waypoints 0,1....x with a simple text-writer c# program and then import it into a SWS path.

    Thanks a lot !
    Ps: A example will be appreciated.
    Ps2: Great Job! Very useful and easy to work with.
     
  24. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi @Milox_, please see my last post for runtime path creation. If you want to create waypoints in the editor, not at runtime, then you simply need an editor script (UnityEngine.Editor namespace) instead.

    All storage files (txt, xls, database) differ in implementation, so its hard for me to provide a sample here. For example, with a txt file, you could have each waypoint position in a separate line and let your editor script loop over all of them for processing.
     
    Milox_ likes this.
  25. Milox_

    Milox_

    Joined:
    Nov 25, 2016
    Posts:
    2
    Thanks a lot, man. I don't know that Unity option (but I can investigate).
    By the way, the "external editor" was a way to generate the points, but with a simple list in a txt file work for me.
    I'll try the editor script.

    Thanks again !

     
  26. James-Williams

    James-Williams

    Joined:
    Aug 30, 2016
    Posts:
    26
    was this issue ever figured out?
     
  27. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Yes, it was. The problem was putting the first and last waypoint at the exact same position, where the tweening logic tries to insert an (unnecessary) curve. There are multiple solutions to that, one being having a little bit of an offset between both waypoints, or disabling closed loop.
     
  28. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    v5.3 is live:
    - added 'Draw Direction' toggle to paths for drawing waypoint rotations
    - added new rotation mode on splineMove: lerp between waypoint rotation
    while moving. This mode is added via new dropdown 'Waypoint Rotation',
    which gets visible in the movement inspector if 'Path Mode' is set to
    'Ignored'. Note that this is an experimental feature and might change.
    - added new scene 'Example10_WaypointRotation' to showcase the new mode
    - added button on PathManagers to update waypoints from children objects
    - added runtime path creation sample to scene 'Example7_Runtime'
    - added rotation handle to waypoints for rotating them in the editor
    - changed free move handles on all waypoints to editor position handles
    - changed position handles only being visible for the selected waypoint
    - position/rotation handle is visible depending on selected editor tool
    - fixed undo/redo of bezier path control point position changes
    - DOTween updated to 1.1.340

    The new (experimental) waypoint rotation mode in action:

     
  29. nburlock

    nburlock

    Joined:
    Apr 11, 2013
    Posts:
    65
    I just added this to my project (not used ti before) and it won't compile with the following error repeated six times in different parts of the splineMove file:

    Code (CSharp):
    1. Assets/SWS/Scripts/Movement/splineMove.cs(368,52): error CS0122: `DG.Tweening.Plugins.Core.PathCore.Path.wpLengths' is inaccessible due to its protection level
     
  30. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Do you have an older version of DOTween in your project?
     
  31. nburlock

    nburlock

    Joined:
    Apr 11, 2013
    Posts:
    65
    OK found it. Another plugin included an older version of DOTTween.
     
  32. arvzg

    arvzg

    Joined:
    Jun 28, 2009
    Posts:
    619
    Hey @Baroni how do I make sure my NPC is facing in a certain direction at the end of his path? For some reason when he finishes his path he instantly turns around in some arbitrary direction
     
  33. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi @arvzg, you could add an event at the last waypoint overwriting its rotation. But I'm more interested in why this is happening, if you could send me a minimal repro project via email or steps how to reproduce this in the example scenes, that would be great.
     
  34. arvzg

    arvzg

    Joined:
    Jun 28, 2009
    Posts:
    619
    @Baroni I recreated the path again, this time without touching any rotational stuff, and it seems to be working fine now. The NPC just stays facing the last direction it was heading in, which is what I want.

    I'm not sure what I did last time, I did mess around with the experimental rotations feature, maybe that caused things to bug out a bit?

    If I manage to reproduce it again I'll send it to you, thanks!
     
    Baroni likes this.
  35. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    924
    Hi,

    I was looking for a simple path editor, mostly because I need a quick visual way to build paths.

    I have to implement a crowd system (2D) that takes the current camera bounds in account to recycle a person moving out the camera to make it re enter the other side with some randomization.

    For this, I'd need the path system to:

    1) be able to get the Y position in the path, or the percentage along the path or between nodes to be able to move an object right outside from the camera bounds at a determined X position. In a manner that works very similar to a f(x) function.
    2) be as performant as possible since I'm on mobile. I may also not need splines if the moving direction vector of the entity I'm moving is not changing from a node to another (segmented/broken line).
    That is, I don't want the entities on a broken path to continuously recalculate direction on a flat line between two points, but only when reaching a path node.
    Performance-wise, I may also use splines or other types of controlled smoothings if the performance hit on the update function for every entity (I guess 30 entities at a time or so) isn't excessive.
    3) I should be able to deactivate instances on a path, and let them resume in any moment)
    4) I really need a way to vertically "drop" instances on a path, so a method to get a Y for every X should be provided or be easy to implement. Since the camera may teleport along with the player, I need to scatter objects on a path (it's a side view game, much like a platformer) randomly inside the camera frustrum (well, I actually use a orthographic camera).
    5) should be easy to setup a path in the editor, possibly being able to reorder the points in the path list from the inspector, or insert a node at a certain position to refine the path.

    I'm kind of in a hurry because I've got a deadline relatively soon.

    Is SWS the right asset for me?

    Thank you,

    Kind regards,
    Alessandro Salvati
     
    Last edited: Jan 3, 2017
  36. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hello @NeatWolf,

    since you've posted this question for three different waypoint systems (including ours), let me start by saying that the movement implementation in SWS takes a different approach. Due to the integration of DOTween, movement routines here are tweens - fixed animations along a path - not calculations done per frame/update. They get initialized at the beginning and then the overhead is gone. But this also comes with the limitation that you can't change paths at runtime without restarting the tween. Now, regarding your questions:

    1) Not really sure what you mean by that. However you can get the percentage of the tween using public DOTween accessors.
    2) Hope I've clarified the performance above. Updates for hundreds of tweens on the CPU are not the issue - you will run into limitations of the GPU first.
    3) The movement script has Pause() and Resume() methods.
    4) You can let objects start at pre-defined waypoints, insert waypoints at runtime, or let an object start at a percentage value on the path. There is no "get closest point on path" method currently.
    5) All of that.

    Nobody uses SMS anymore, WhatsApp is the thing now :p
     
  37. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    924
    LOL! Sorry about the typo :)

    Yes, I needed to check who was more responsive with feedback in first place :p

    4) That's was actually the method I needed most. Retrieve the Y position at a certain path's X position.

    I guess I'll have to implement that by myself :)

    Thanks for the quick answer!

    Cheers
     
  38. Dosei

    Dosei

    Joined:
    Jun 7, 2014
    Posts:
    2
    Hello, @Baroni !
    I have been using SWS for some months now and it has been very useful. Thanks for developing it.
    I have a little problem, similar to the one @Osteel described: I try to lock my agents' Z rotation, but it doesn't seem to work. This is more apparent on paths that move up/down and to the sides (not flat on a plane). Also, when I lock rotations on X, it seems to block BOTH the X and Z axes.

    Thanks for your help!
     
  39. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi @Dosei, could you link the post by Osteel you are referring to? Also, since rotation/quaternions are a wild thing to play with, it would be extremely useful for me if you could send a simple sample / repro via email so I can take a look whether it's something with your movement settings, the path, both, or a bug.
     
  40. Dosei

    Dosei

    Joined:
    Jun 7, 2014
    Posts:
    2
    @Baroni this is the quote. It's mainly point 3 that we have in common:

    Is it okay if I send you a unity package at info [at] rebound-games [dot] com ?
     
  41. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
  42. Mark_T

    Mark_T

    Joined:
    Apr 25, 2011
    Posts:
    303
    Hi,
    What would I need to make your asset work seamlesly with Core GameKit? My goal is to make a tower defense game and I really like the movement control SWS provides. The goal here is to be able to use both assets to create my own game design/mechanics. I have your 3D Tower defense kit, it's a solid asset, with a classic game play. I need to do my own thing, and by using SWS abilities with Core GameKit features I can get the freedom I need to create my own game mechanics.
    What would I need to make these 2 assets work? Would it be possible to integrate these 2 assets?
    I asked the same question in the Core GameKit thread.
    Thanks in advance for your help.
     
  43. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi @Mark_T, what exactly would you like to do with Core GameKit? Pooling & Spawning? If you just want to spawn enemy prefabs with a movement script already attached to them, you just have to disable 'OnStart' on the prefab's movement script. Then after spawning a prefab instance, assign a path to the path container and call StartMove on it.
     
  44. Mark_T

    Mark_T

    Joined:
    Apr 25, 2011
    Posts:
    303
    Looks pretty simple, but for a non-progarmmer like me it's rocket science. :):(
     
  45. Oshigawa

    Oshigawa

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

    i've got a simple question. I'm using your asset for 2D shooter game, and i'm trying to do this (there are just instantiated prefabs, not actually moving on the path):



    Spaceship should follow the path and shouldn't rotate BUT it should flip on X axis when it starts moving on the positive X axis (i.e. right). Now, when i set path mode to ignore in splinemove script, it moves without rotation, but without flipping. But when i set Path Mode to Sidescroller 2D and lock Y rotation since it should only flip on X axis i get this:

     
  46. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hey @Kruko, since you basically want no rotation at all expect the 'flipping', I would treat that as separate method call. You can set this up with events in the inspector, there is even a method for it already :)

    - set the path mode to 'Ignore'
    - attach the EventReceiver script to your moving object
    - add a waypoint to the path, and position it where the object should flip
    - in the movement script, expand the events section, and add an event at the waypoint you just added, referencing the EventReceiver.RotateSprite method with a value of 180 (if it should turn left, otherwise 0).

    RotateSprite.png

    P.S. forget what I am saying, it is even simpler if you just use Sidescroller2D and lock the X rotation - same effect, without events. The object is rotating on the Y axis so you should not lock that.
     
  47. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    @Baroni

    First of all, thanks for the swift answer!

    I've tried it before, but the object always flips when change of direction on the Y axis occurs instead on change of direction on X axis. Then i noticed i use Catmull Rom path type and tried using the Linear path type instead. And indeed it works when i use Linear path type, but the path is too "edgy" that way, there's no smoothing between the points.

    Is there a way to use Catmull Rom and make object behave as desired without implementing the method or make the path smoother in Linear mode?

    Edit: Aaaah, PATH DETAIL! :D

    I hope cranking it up to the max is not too resource intensive. For knowledge sake, why does it act like that when using catmull?
     
    Last edited: Jan 13, 2017
  48. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Setting the path detail to the max does have an impact on performance indeed, which could be compensated with only few moving objects at the same time. As for why on catmull: honestly I don't know. Both linear or curved tweens are created by DOTween and uses its rotation settings, so I'll have to dig a bit deeper on this one.
     
  49. Oshigawa

    Oshigawa

    Joined:
    Jan 26, 2016
    Posts:
    362
    Yeah, i'm not sure that kind of behaviour is meant to be :)
     
  50. coverpage

    coverpage

    Joined:
    Mar 3, 2016
    Posts:
    385
    Hi, I've been using this asset for a couple of days. I generate spline waypoints at runtime and use your move animator helper script to animate my mechanim based on the spline movement. It works nicely.

    But I have trouble incorporating jump animations. Tried to calculate waypoints difference in vertical height and calling a jump animation, but haven't been able to achieve anything decent yet.

    Do you have any solutions for "jump" or "airborne" animation?