Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Simple Waypoint System (SWS) - Move objects along paths

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

  1. RichCodes

    RichCodes

    Joined:
    Apr 3, 2013
    Posts:
    142
    I'm still new to the whole idea of pathing so I don't know if this is a commonly used solution or not that I have come up with. I just wanted to share in case anyone else finds themselves in the same situation.

    Situation: I have a racing game, I want to be able to switch lanes back and forth without starting over at the beginning. I want to be able to use bezier paths.

    Problem: As told above, due to internal calculations bezier paths cannot be switched mid-path.

    My solution: Use only one path in the exact middle of the roadway, no matter how many "lanes" are involved. Set a parent object to follow the path and have your vehicle switch lanes simply by altering its position relative to the parent. Not only does it allow you use simulate switching lanes on a bezier path, but also allows you to make only one path instead of 2,3, or more depending on your situation.

    $raceex.PNG
     
  2. Peter Hou

    Peter Hou

    Joined:
    Oct 12, 2010
    Posts:
    66
    Hi,

    It appears that I've run into a problem with the lookAhead variable. Isn't it possible to change this value in runtime? It only updates if I use teleport or reset the movement resulting in a visible hiccup.
     
  3. lepri55

    lepri55

    Joined:
    May 6, 2014
    Posts:
    2
    I recentely discovered the SWS and really liked it. Actually, I am using it for a serious game I am creating. That is why I need your advice about something and it would be great if you could help me with it.
    I have to create a trigger, which will make an object switch from one path, to another, no matter where it is located along the first path when this trigger is activated. Does SWS offer any methods/functions that would help me with this situation?
    So, if you could indicate me some path to follow about this problem, I would really appreciate it :D
     
  4. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Great idea, thanks for sharing!

    Hi Peter,

    never tried this myself actually, but it could be that the lookAhead parameter falls under the same restrictions as other runtime changes to tweens created by HOTween (reset to change). If that's the case, a guided gameobject and Unity's lookAt method would be an alternative to this limitation.

    Thanks for using SWS! You can call SetPath(WaypointManager.Paths["your path name"]) at any time on a movement script to change its current path. Have a look at our scripting reference for all available methods. The runtime example scene also has a sample and demo code for switching paths using a button. Note that when switching a path, your walker object will walk to the first waypoint of the new path.
     
  5. masha_mustakim

    masha_mustakim

    Joined:
    May 21, 2014
    Posts:
    6
    Hi,

    I just bought SWS. This is really cool.

    I want a gameobject instantiated in a random position on the line (which I can do myself :p) and make it move along the path from that position. How can I do this ?

    I guess it should work with orient to path. But, it's not working :(
     
  6. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Hi masha_mustakim,

    thank you very much! Usually, SWS moves gameobjects from waypoint to waypoint (segments), so you could alter the "currentPoint" variable on the movement script (splineMove and navMove) to start from a waypoint/segment on the path.

    The minimalMove movement script is a bit different, as it considers the full path as a single segment. This allows you to start moving and then call tween.GoTo(time value) on it to fast-forward to a specific position on the path, e.g.:

    Code (csharp):
    1. minimalMove minMove = gameObject.GetComponent<minimalMove>();
    2. minMove.StartMove(); //start movement
    3. yield return new WaitForEndOfFrame(); //wait for tween initialization
    4. minMove.tween.GoTo(5); //fast-forward to 5 seconds
    Edit: orientToPath is used to rotate your object to the direction of the path.
     
  7. masha_mustakim

    masha_mustakim

    Joined:
    May 21, 2014
    Posts:
    6
    omg! only twenty mins. :O

    I am more than grateful for your help. I expected I will get a reply tomorrow :p.

    Thank you very much.
     
  8. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    You're welcome :)
     
  9. masha_mustakim

    masha_mustakim

    Joined:
    May 21, 2014
    Posts:
    6
    Hi,

    me again :D ... i need a small advice from you. I am new in this waypoint system and tween engine. Would creating many waypoints ( say 1000 waypoints for single tween) result in performance drop ? I am up for building a 2d game and targetting android mobile devices.
     
  10. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Waypoints are just empty gameobjects, which are handled pretty well by Unity. As you mentioned, this would still result in a single tween per object and HOTween really takes care on the part of performance for multiple tweens. I don't think that this would cause serious trouble, but you should test it on the device at a later stage.
     
  11. masha_mustakim

    masha_mustakim

    Joined:
    May 21, 2014
    Posts:
    6
  12. Pajaroide

    Pajaroide

    Joined:
    Sep 19, 2012
    Posts:
    34
    Hello! I've been using SWS and I noticed something that would increase my workflow tremendously:

    After creating a path, it would be awesome to have an option on the "Path Manager" (script) to select right then and there the game object I want to move using that path.

    I think the current workflow of creating the path, then adding a script to the object I want to move and then selecting the path I want to use in that script is a little bit too long.

    Anyway SWS is an awesome asset, thank you for creating it! ;)
     
  13. justkedin

    justkedin

    Joined:
    Sep 19, 2013
    Posts:
    9
    Hi! I just would like to ask if SWS supports Unity 2D (4.3.x) and is it possible to create paths of an object during runtime? If so, do you know any tutorials or guides that may help a newbie like me? Thank you very much!
     
  14. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Hi Pajaroide,

    thanks for your feedback! I think the current workflow really fits to Unity in terms of modular design. As we have various movement scripts and some of them are limited to a specific path type (e.g. bezier paths), just adding a gameobject to a path couldn't achieve the result you're after. You could make prefabs of your objects to save 2 seconds ;)

    Welcome to the forum justkedin,

    SWS' movement scripts can be attached to any gameobject in Unity (2D or 3D). Also, paths have an array of gameobjects, which work as waypoints - basically the process for runtime instantiation is to create a gameobject and attach the path manager script to it, then instantiate and re-position multiple waypoint gameobjects and assign them to the path manager waypoints array. Basic code samples for this can be found in Unity's scripting reference (link)
     
  15. justkedin

    justkedin

    Joined:
    Sep 19, 2013
    Posts:
    9
    Just wanted to make sure these features are available before I purchase SWS :)
    Bought it and will start learning to use now. Thanks a lot sir Baroni!
     
  16. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,061
    How can you get this to make the character have a new animation? also can we control the frames per second of an animation?
     
  17. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Animations are controlled by Mecanim Animator Controllers (link), there are a few good Unity tutorials on YouTube. The controller we used contains a speed and direction value, with transitions between different animations. Our "MoveAnimator" script sets these animation values based on the tween/agent speed and direction. I'm not that much into animation settings, but you should find something on the forums about animation frames per second.
     
  18. Julian-S

    Julian-S

    Joined:
    May 31, 2013
    Posts:
    73
    Hello! So I am looking to create a waypoint system on a moving boat (in all axes) so that all the crew can navigate around the boat when both stationary and moving. Is this doable with SWS?

    Thanks!
     
  19. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Hi Julian!

    If you're looking for fixed paths, parented to the boat (e.g. a path from the left side of the boat to the right side and this path moves with it), then that's totally doable with our "local" checkbox on spline movement scripts, which make use of HOTween's local path setting. Our webplayer demo has a sample with local and moving paths, have a look at the advanced example scene (there's a rotating path). The navmesh scripts in SWS would not be the best fit, as Unity's NavMesh system does not support position changes.
     
  20. Julian-S

    Julian-S

    Joined:
    May 31, 2013
    Posts:
    73
    Awesome to hear! Yes it would be fixed paths. Is there a sort of demo/tutorial included to learn how to do this? (just want to make sure)
     
  21. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Great. The package contains a short introduction on how to create paths, movement scripts and other functionality. Local paths can be achieved by toggling a single checkbox, nothing too fancy ;) As I mentioned above, our "advanced" scene already showcases local paths.
     
  22. Julian-S

    Julian-S

    Joined:
    May 31, 2013
    Posts:
    73
    Excellent, well I will be purchasing then. Thanks for quick response and help, and you know, for making it.
     
  23. PeterShoferistov

    PeterShoferistov

    Joined:
    Sep 22, 2013
    Posts:
    59
    Last edited: Jun 1, 2014
  24. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Hi there,

    I've brought this up with the developer of HOTween here and will add it to SWS immediately once it's available.
     
  25. PeterShoferistov

    PeterShoferistov

    Joined:
    Sep 22, 2013
    Posts:
    59
    Cool, thanks. This feature is very much needed for 2D
     
  26. justkedin

    justkedin

    Joined:
    Sep 19, 2013
    Posts:
    9
    Hello again :D Just a quick question: where's the speed of SWS based from?
    I mean, because I have a 'map' and 1 pixel represents 1 meter. I wanted to assign speed like it would be in m/s.

    Hope you can enlighten me regarding this. Thank you!
     
  27. goy

    goy

    Joined:
    Jul 15, 2012
    Posts:
    10
    Hi. I bought your SWS yesterday and I totally like its simplicity, but after two hours I found a little bug in there.
    If a message will be sent, because the path is at its end and if the path gets changed in the method from the message, everything stops.

    The reason is, after message.execute you call ReachedEnd and it stops the new path.
    I did a correction on splineMove Row 402.

    Code (CSharp):
    1. //memorize that manager
    2. PathManager F_lastManager = pathContainer;
    3.  
    4. ...
    5.       messages.Execute(this, currentPoint);
    6. ...
    7.  
    8. //if path is still the same, it hasn't been changed and is ready to be killed
    9. if (pathContainer == F_lastManager) {
    10.    //reset loop index
    11.    startingPoint = 0;
    12.    //differ between tween options at the end of the path
    13. StartCoroutine(ReachedEnd());
    14.  
    That fixes it. You're welcome. :)

    Two more things.

    For my convenience I added the variable
    public MonoBehaviour TargetReciever;
    in the MessageOptions so the message will be send to this object instead to the owner of the splineMove.
    Just my two cents for keeping the simplicity and not creating a Reciever Class for this everytime. :p

    But why is MessageOptions so complicated with this many arrays instead of a simple class holding a single row of information? Just curious.
     
  28. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Hi again ;)

    Speed based tweens are moving x Unity units per second: source.

    Hi goy, thanks for figuring this out! I'll have a look at your fix and include something similar in the next release. The Message class has undergone major changes in the 4.x release and "grew over time" in complexity, you're right to say that this could also be a list of data classes.
     
  29. Soumikbhat

    Soumikbhat

    Joined:
    Nov 23, 2013
    Posts:
    110
    Hello I'd like to achieve this :
    The enemy would normally walk along the path set by the waypoints (when the player is not around), and when the player is within a certain range of the enemy, the enemy would abandon the waypoints and chase down the player until death, suppose I want this script to be executed when the player is within 5 units of the enemy

    Code (JavaScript):
    1. var enemy : Transform;
    2. var player : GameObject;
    3. internal var animator : Animator;
    4. var distance : float;
    5. function Start()
    6. {
    7. player = GameObject.Find("player");
    8. //enemy = GameObject.Find("soldier");
    9. animator=GetComponent(Animator);
    10. }
    11. function Update() {
    12. distance = Vector3.Distance(player.transform.position, enemy.position);
    13. //Debug.Log("distance is " + distance);
    14. if(distance <10)
    15. {
    16. transform.LookAt(player.transform);
    17. animator.SetFloat("Run", distance);
    18. }
    19. //distance = Vector3.Distance(player.transform.position,enemy.transform.position);
    20.  
    21. }
    How to achieve this using SWS?
     
  30. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Our example scene "Example4_Advanced" has a sample on triggering a navMove component to leave its path, walk to another position and return back to its path afterwards. Look out for the "Messages" header and the walker object "Walker (Path5)".

    This walker object has a message set up on the last waypoint, that calls the SetDestination method on MessageReceiver.cs. This method already has a lot of functionality that you need. You could write your own script based on this method and call it on the enemy navMove component when the player is nearby (e.g. OnTriggerEnter).
     
  31. justkedin

    justkedin

    Joined:
    Sep 19, 2013
    Posts:
    9
    Hmm.. by "x Unity units per second", did you mean that if I assigned 1 as the speed of the walker, it would move by 1 Unity unit per second? Thanks a lot for the help! And really really thank you for creating such a great asset! :)
     
  32. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Exactly. You're welcome :)
     
  33. JohnRossitter

    JohnRossitter

    Joined:
    Dec 18, 2013
    Posts:
    1,027
    I posted this over on the Rebound Website, but figured this was probably a better place:

    Hello everyone.

    I'm working on a scene in Unity for SWS and am having a bit of a hiccup with it.
    My Scene is setup with 6 Bezier Paths on it.
    My main camera is set to consume the SWS.bezierMove class, but I'm making these assignments on the fly via the API.

    Here is an example of my code:

    SWS.bezierMove myMove;
    myMove = (SWS.bezierMove)mainCamera.gameObject.AddComponent<SWS.bezierMove>();
    myMove.pathContainer = (SWS.BezierPathManager)SWS.WaypointManager.Paths["0_To_1"];
    myMove.pathType = Holoville.HOTween.PathType.Curved;
    myMove.onStart = true;
    myMove.orientToPath = true;
    myMove.lookAhead = 0.0f;
    myMove.lockAxis = Holoville.HOTween.Axis.Z;
    myMove.sizeToAdd = 0.0f;
    myMove.timeValue = SWS.bezierMove.TimeValue.speed;
    myMove.speed = 20.0f;
    myMove.loopType = SWS.bezierMove.LoopType.none;
    myMove.lockPosition = Holoville.HOTween.Axis.None;

    For the most par this code works perfectly for me, with the exception that when I assign a new path to the camera at runtime, it makes a hard jerk to face the new path origin point. I was wondering if there was a more graceful way to handle this (ie rotate on the Y axis to face the new path first).

    I have tried setting the OrientToPath option as well as the LookAhead, just cant seem to get it to glide smoothly from one path to another.

    Thanks
     
  34. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Hi JohnRossitter,

    originally, our support forum was created to easily browse and link answers to common questions. I'd like to keep everything in one place and replied to your thread in our forum.
     
  35. epsilonstudios

    epsilonstudios

    Joined:
    Feb 20, 2012
    Posts:
    15
    Hi, I really want to get my hands on this asset but I'm version locked to 4.2.2. Does it work with this version at all?
     
  36. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Hi epsilon,

    SWS version 4.x uses the new undo system introduced in Unity 4.3, which is not backwards compatible, sorry.
     
  37. Shirts

    Shirts

    Joined:
    Nov 4, 2012
    Posts:
    8
    When I switch and teleport my object to another path, I'd like to move to the closest waypoint nearest to my previous path? Is this possible?

    thanks for your response in advance.
     
    Last edited: Jun 15, 2014
  38. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Hi Shirts,

    the current version has a design issue regarding teleport functionality. If you're using splineMove, please comment out
    Code (csharp):
    1. currentPoint = 0;
    in its Stop() method (investigated and fixed in the coming version). After that, the following code snippet lets an object start on another path at a specific waypoint:

    Code (csharp):
    1. splineMove move = gameObject.GetComponent<splineMove>();
    2. move.currentPoint = set this to your specific waypoint index
    3. move.SetPath(WaypointManager.Paths["your new path name"]);
    It has to be a waypoint, as movement can only start on path segments.
     
  39. Shirts

    Shirts

    Joined:
    Nov 4, 2012
    Posts:
    8
    thank you for your timely response. I edited the post probably before you saw it.

    When I switch and teleport my object to another path, I'd like to move to the closest waypoint nearest to my previous path? Is that possible to check for closest waypoint possible and teleport to that waypoint?

    sorry, and thanks again.
     
  40. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Well there's no built-in method for that, but you could get the waypoint array of the PathManager component, iterate over it and do a simple Vector3.Distance check for each of them to find the nearest one. Then save its index and set it as currentPoint variable.
     
  41. Shirts

    Shirts

    Joined:
    Nov 4, 2012
    Posts:
    8
    thanks for your help, Sir.
     
  42. lepri55

    lepri55

    Joined:
    May 6, 2014
    Posts:
    2
    Hi, thanks a lot for helping! I recentely finished writing the script and it works fine. :)
     
  43. justkedin

    justkedin

    Joined:
    Sep 19, 2013
    Posts:
    9
    Aaaand I'm back xD
    I wanted my walker(which is a prefab) to rotate and face the direction it's going to walk through. I've added the MoveAnimator script, and Animator component and set the Controller with MoveController2D (as my program is in 2D). I've also tried using the MoveController to try if it would work, but it didn't. Did I miss anything? :(
     
  44. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Hello again ;)
    Have you had the chance to look at the 2D sample included in the example scene 4? There's a sprite, which rotates on its y-axis at the end of the path by using messages. One of the newer versions of HOTween has "real" 2D rotation along the path, but I'm facing a show stopper in my current implementation that needs to be fixed first. It should be out in the course of next week.
     
  45. justkedin

    justkedin

    Joined:
    Sep 19, 2013
    Posts:
    9
    Hmm as I have understood, if I use the message thingy, I would need to input the rotation value. However, my path will be defined during runtime so I think it would be hard to know the values that I need to assign to the message.
    I have seen the 'look ahead' and 'delay' samples in the Example4 scene and I think what i need is the 'orient to path' feature. However, when I try to check it in my walker, the walker just disappears during runtime @_@ I tried changing the lock axis and none of the choices (x,y,z,w) changes the output. Does this feature not support 2D? :(
     
  46. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Orient to path will support Unity's 2D view with the new version of HOTween.
     
  47. justkedin

    justkedin

    Joined:
    Sep 19, 2013
    Posts:
    9
    Ohhhhh. Ok thanks a lot sir! I really look forward to it~
     
  48. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Version 4.0.2 is now live and contains HOTween's new 2D orient to path behavior as of version 1.3.320:
    (http://forum.unity3d.com/threads/ho...nity-tween-engine.118515/page-35#post-1673275)

    v4.0.2
    - fixed message position field resetting on bezierMove
    - splineMove, navMove: changed currentPoint index not resetting when
    calling Stop(), currentPoint now only resets when calling ResetMove()
    - added HOTween's new 2D option to orientToPath enumerator
    - HOTween updated to 1.3.320
     
  49. Ceciaman

    Ceciaman

    Joined:
    Jul 30, 2013
    Posts:
    26
    Baroni Hello I have a question for you.
    I'm working on a horse race with 8 independent path composed of 12 waypoints.
    everything works fine except when the horse is close to its waypoint is a slight snap back.
    This problem is present on all the path and with all the horses.
    how can I solve it?
     

    Attached Files:

  50. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,334
    Hi Ceciaman,

    which movement script do you use? minimalMove is a performance efficient script that does not consider waypoints (for more fluent movement), but the path as a whole, have you tried it?
     
unityunity