Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Simple Waypoint System (SWS) - Move objects along paths

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

  1. desyashasyi

    desyashasyi

    Joined:
    Nov 22, 2012
    Posts:
    73
    OK Baroni, Thanks. But I have difficulty, how to start movement from specific index of waypoint. For example, Now walker is position in index 6 waypoint A, then by looking closest index in another waypoint, say waypoint B, i want to change the path manager from waypoint A to waypoint B and start walker movement from index of waypoint B, for example index 9.
     
  2. desyashasyi

    desyashasyi

    Joined:
    Nov 22, 2012
    Posts:
    73
    Oooo I intent to use navMov, because I want to navigate walker following the waypoint but freely to move to another place by custom script/playmaker action.

    First I tried to modified SWS_StartMovement to specific point. But I haven't luck.

    Code (CSharp):
    1.  void Execute()
    2.         {
    3.             var go = Fsm.GetOwnerDefaultTarget(walkerObject);
    4.             if (go == null) return;
    5.             navMove move = go.GetComponent<navMove> ();
    6.             move.currentPoint = newPoint.Value;
    7.             go.SendMessage("StartMove");
    8.         }
     
    Last edited: Feb 9, 2015
  3. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    @desyashasyi Why so difficult? ;)

    upload_2015-2-10_1-16-29.png

    PlayMaker's SetProperty action allows you to do that already. After you've set the currentPoint you can call the "SWS_Start Movement" as usual.
     
  4. JuanMaldonado

    JuanMaldonado

    Joined:
    Oct 12, 2012
    Posts:
    27
    Hello!
    Please help me :)
    I'm using a simple navemesh system with agents going along a smoothed path with the Nav Move Script on the agent just like the example on the Navmesh scene with the closed loop feature. The problem i'm having is when I increase the speed of the agent, it becomes harder for it to reach the waypoint and sometimes it gets stuck and starts looping around a waypoint.

    Is there a way to make the waypoints larger or have a bigger trigger area or any other solution? More or less like a checkpoint area for a vehicle. Any ideas?
     
  5. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    Hi Juan,
    you are looking for the "stopping distance" on your NavMesh Agent component:
    http://docs.unity3d.com/Manual/class-NavMeshAgent.html
     
    JuanMaldonado likes this.
  6. saucer78

    saucer78

    Joined:
    Jul 6, 2014
    Posts:
    66
    Hey Baroni, or anyone who may be able to help....

    I'm still very new to Unity, but am trying to use the suite to create passive experiences for the Oculus Rift. (Simple, scripted 3D demos that involve no input from the user.) I've had some luck with the more basic portions of the program, but am feeling overwhelmed with the animation and mechanim capabilities. I've been reading and watching videos all afternoon and cannot seem to digest much of the information, especially since most doesn't involve the integration of a path like SWS.

    Do you know of any simpler tutorials regarding animation events for pre-scripted characters? Is it possible to summarize this for me in a short post? All I'm wanting to do is use SWS to plot a path for a flying dragon (which is already rigged and includes a dozen animation clips) and have that dragon change his animation at certain points along the path... which I assume are known as "events." There are SO many variables for the robust Animation and Animator widgets that I have no idea what does and does not work with SWS.

    If there are any video tutorials expanding upon the "Advanced" section of your documentation, I'm sure it would help me greatly. Being so new to the program makes understanding the few paragraphs of what may be perfectly explanatory to educated users is still over my head :(

    Thanks for any help at all!
     
  7. AdeelAbbas

    AdeelAbbas

    Joined:
    Jul 18, 2014
    Posts:
    22
    Hi everyone
    When I increase the speed of SplineMove script then my controller(Move left and Move Right ) does not work. It works fine with only less than 8 speed.Please reply Thanks in advance.
     
  8. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    @saucer78
    Hey, the basics first: SWS is not really connected with Mecanim, as both could be used separately to create movement behavior. SWS uses tweens for movement, while Mecanim uses the force of animations to drive objects (Root Motion). Root motion can also be disabled in Mecanim, so your objects stay in place while animated.

    Simple Waypoint System creates the tween which moves the object, then passes the current speed value to Mecanim, which plays the correct in-place animation (e.g. idle or walk). In the sample scenes, this is being done with the Mecanim MoveController (Examples > Assets > Controller, double click on it) and the MoveAnimator script. The controller has all the animations and transitions set up, so it only needs to know the current speed and direction to play the corresponding animation.

    I don't know whether you actually need to use Mecanim for your dragon, but you could also set it up in the legacy Animation component. Then at a waypoint or trigger, you could just get the Animation component via script and call .Play("new clip name") on it to let it play a specific animation. This would be absolutely sufficient for a simple animation control and doesn't involve Mecanim at all.

    @AdeelAbbas
    Hi, could you explain which controller you mean? Any chance for me to reproduce this in the sample scenes?
     
  9. JuanMaldonado

    JuanMaldonado

    Joined:
    Oct 12, 2012
    Posts:
    27
  10. AdeelAbbas

    AdeelAbbas

    Joined:
    Jul 18, 2014
    Posts:
    22
    Thanks for your reply Baroni Actually I want to move my character left and character right like subway surrfers but problem is that when I trigger it for left or right It changes its z position while I am temporary saving z position but on trigger it moves back from position means e.g. If on Waypoint1 I move left Its position z comes to Waypoint0. Can you please tell me whats problem with this. I am using SplineMove for moving the Character.
     
  11. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    By "trigger it for left or right", do you mean that you switch the path? If you call SetPath with a new path, the default logic sets your object back to the first waypoint. This is the desired behavior, as it is not (easily) possible to start a new tween at the same position on a different path.
    Instead, it is best practice to only use one path and make your character a child of the moving object. This way you can modify the character position relative to the driving object on all axes, without affecting the actual movement. See this post for a similar solution.
     
  12. AdeelAbbas

    AdeelAbbas

    Joined:
    Jul 18, 2014
    Posts:
    22
    Thanks for your reply!
    I am using only one path. If I try to move from that path to left or right then my character z position changed means it comes on back e.g. My character is on Waypoint1 and then I move left using transform.position.x+1f. then My z also changes it comes back to Waypoint0 while moving.
    once again thanks for your reply.
     
  13. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    @AdeelAbbas
    Are you moving the path or the character? If you move the character, try using transform.localPosition on the child object (not the moving object with the movement script itself). If you are moving the path, check that your character is a child of the path and you've enabled "local" on the movement script.
     
  14. AdeelAbbas

    AdeelAbbas

    Joined:
    Jul 18, 2014
    Posts:
    22
    Baroni Thanks for reply!
    Actually I am moving character and on character I have script of splineMove.cs and my CharacterController script. I just want to smooth transformation of my character on left and on right side.
    Once again thanks for your reply.
     
  15. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    I'm convinced that it won't work if you have two movement scripts on the same gameobject, they must be childs of each other. Could you send me your current attempt at this via email, so I can try to set this up for you?
     
  16. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    Free asset giveaway!

    Starting next month, we will be giving away this or one of our other assets (http://u3d.as/2uX) to one lucky follower every month. Follow us on Twitter @Rebound_G to stay updated and don't miss the chance to win!
     
    AdeelAbbas likes this.
  17. AdeelAbbas

    AdeelAbbas

    Joined:
    Jul 18, 2014
    Posts:
    22
     
  18. AdeelAbbas

    AdeelAbbas

    Joined:
    Jul 18, 2014
    Posts:
    22
    Hi everyone Can someone please tell me how to move my character on slope because when I move to path then it never move on slopes. My slopes are on my path which is moving by splineMove.cs script
     
  19. AdeelAbbas

    AdeelAbbas

    Joined:
    Jul 18, 2014
    Posts:
    22
    Hi everyone Can someone please tell me how to stop movement on path. Because I want to stop my character on some collider trigger.
    thanks in advance.
     
  20. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    @AdeelAbbas
    Thanks for the sample, I've seen that you didn't set up the character as I suggested before. There is too much for me going on in your scripts that I can't figure out, so please try this setup:

    Olmide_Main (new Gameobject, splineMove)
    --- Olmide 1 (your Character object, Animation + Char Controller + Animation Handler + Path Detection)

    It works with this setup, but your left/right speed is way too high and you are manipulating the z position by script somehow. Your script should only affect the x axis. Regarding "move my character on slope", I don't know what you mean by that, coud you explain a little bit more?

    Stopping character on a path: yourSplineMoveComponent.Stop();
     
    AdeelAbbas likes this.
  21. AdeelAbbas

    AdeelAbbas

    Joined:
    Jul 18, 2014
    Posts:
    22
    Great Thanks for your co-operation!
    Can you please tell me Can I move using unity Character Controller becuase I want to just get waypoint array so I can move on path.But move using my own Controller Script. Means I want to move using (transform.TransformDirection) but On your given path.
     
    Last edited: Feb 25, 2015
  22. AdeelAbbas

    AdeelAbbas

    Joined:
    Jul 18, 2014
    Posts:
    22
    This is my slope and I want to move my character on it. I use Character Controller and NavMesh Agent both but both are not working for me. slope1.png
     
  23. AdeelAbbas

    AdeelAbbas

    Joined:
    Jul 18, 2014
    Posts:
    22
    "Stop" can only be called on an active agent that has been placed on a NavMesh.
    "Resume" can only be called on an active agent that has been placed on a NavMesh.
    "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
    I am facing these errors when I attach nanMove script to my character.
     
  24. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    You can get the waypoint array of a PathManager component by accessing its waypoints variable. For the movement part with Character Controllers you would have to code that yourself.

    Thanks for the screenshot. If you are using one of the movement scripts in SWS, usually the moving object follows the path, which would go directly through your object in this image. If you would like to let it jump over it, I would recommend placing a trigger at the beginning of the object and manipulating the character's y-position over time (2 seconds maybe).

    As per error message, your object is not placed on a NavMesh. Did you bake the NavMesh in your scene and placed your character on it?
     
  25. AdeelAbbas

    AdeelAbbas

    Joined:
    Jul 18, 2014
    Posts:
    22
    Thanks for your reply!
    Can you please tell me How I can move my Character on the given Path e.g. I have PathManager name (FirstPath) and I want to move on FirstPath with controllers(Jump,Down, Left and Right) But on PathManager FirstPath. Have this facility available in your package?
     
  26. AdeelAbbas

    AdeelAbbas

    Joined:
    Jul 18, 2014
    Posts:
    22
    Is this facility in package that I want to move my object from PathManager1 waypoint7 to PathManager waypoint7 directly. and could you please tell me updating Y position of character I tried but it doesnt work for me Its again move on path without changing its Y position.
     
  27. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    The example scene "Example6_PathInput" has a sample for moving an object on a path using keyboard input (left, right in this case). I would suggest you take a look at it and see if this fits your project.

    You are asking many times for a "Jump" or "Left / Right" functionality, and I can only give you the same answer as before - this is something you would do in your own code, by modifying the relative/local position of your character (child), not of the object with the movement script! It doesn't have anything to do with Simple Waypoint System, as shown in this post. If you are not familiar with local positioning, you'll find a lot of tutorials or more in-depth topics out there.

    SetPath(PathManager newPath, bool reset) let's you switch to a path at the same waypoint. Your object won't walk there though, it will just teleport to the new path.
     
  28. Gibbonuk

    Gibbonuk

    Joined:
    Dec 10, 2013
    Posts:
    163
    Hi, ive bene looking at this and I'm struggling to work out if it will do what i want, so wondered if you can advise.

    Basically Im trying to think of a basic way to put some planes in the sky and fly around. But there are a few things I want to happen, first is for the patten not to be exactly the same every time and I've noticed you can do set it to random which is great. Another thing is when they get to a way point and choose another i would like them to turn and bank (like a plane) and also not "stop" and turn?

    Is this possible?

    Thanks
     
  29. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    @Gibbonuk
    Hi there, the "random" looptype shuffles an array of waypoints, but this could also result in two waypoints being positioned on the opposite of each other. Then your plane would do a 180 degree turn, which wouldn't look authentic. You would get a more legitimate flying behavior when placing waypoints at runtime, in a specified area, with your own code that only allows for slightly curved paths. You can then use the movement part of Simple Waypoint System to let the plane fly on your path, and additionaly calculate the angle of bank based on the next waypoint position (or a leading object in front of the plane).
     
  30. Gibbonuk

    Gibbonuk

    Joined:
    Dec 10, 2013
    Posts:
    163
    Ok, great thanks.
     
  31. AdeelAbbas

    AdeelAbbas

    Joined:
    Jul 18, 2014
    Posts:
    22
    Baroni thanks for your cooperation.:)
     
  32. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    Version 5.0 is live and not only replaces HOTween with the 400% faster DOTween engine, but also comes with UnityEvent support at waypoints and more flexible movement options!

    v5.0 Full release notes:
    BREAKING CHANGES! PLEASE READ CAREFULLY
    - NEW: HOTween has been replaced with DOTween for 400% faster tweens
    - NEW: Message functionality has been replaced with built-in UnityEvents for specifying target, method, argument in the inspector at waypoints
    - NEW: "reverse" checkbox on movement scripts, allows moving in the opposite direction on the path on a per-walker basis
    - NEW: "startPoint" variable added on movement scripts, allows starting from a different waypoint position on the path
    - NEW: startPoint also works with "moveToPath", e.g. walking directly to the third waypoint, then continuing the path as usual
    - NEW: included DOTween looptype "Yoyo" which lets your object move on the path forwards until the end, then it moves backwards to the start
    - NEW: movement script methods: GoToWaypoint(index), Pause(seconds)
    - CHANGE: BezierMove events can now be called at waypoints too, the setting for messages on percentual path positions has been removed
    - CHANGE: "currentPoint" variable is not meant to be modified anymore for setting a start position, use the new startPoint variable instead
    - CHANGE: minor variable naming adjustments to be in line with DOTween
    - CHANGE: method renaming: ResetMove() -> ResetToStart()
    - DEL: minimalMove movement script removed, use splineMove instead
    - DEL: delay settings removed, use new events and Pause(seconds) instead
    - DEL: PlayMaker action SetDelayAtWaypoint is gone, see the sample scene
     
    Last edited: Mar 4, 2015
    MD_Reptile likes this.
  33. nicholas33

    nicholas33

    Joined:
    Mar 5, 2015
    Posts:
    3
    Hi Baroni,
    When I used previous version ,my game get stutter though the average FPS is 50 . vsync also is tickled. So I download the SWS v5.0 which is so call 400% efficient.However I got the compile error as below after importing the version 5.0. Can you help me?
    Internal compiler error. See the console log for more information. output was:
    Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.

    at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)

    at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0

    at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0
     
  34. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    @nicholas33 Hi, an internal compiler error means something went wrong in the compilation process after import. Please try reimporting it again.
     
  35. nicholas33

    nicholas33

    Joined:
    Mar 5, 2015
    Posts:
    3
    Oh ,I figure out .It needs Unity 4.6 above, my Unity version is 4.5
     
  36. JoeHarry

    JoeHarry

    Joined:
    Mar 7, 2014
    Posts:
    1
    Hi Baroni,

    Great system you've created here, it has really helped out my project.
    I was just wondering, is there a way to ease in to the movement after stopping at a certain point?... rather than an abrupt start after Pause and Resume are called. Apologies if this has been asked already, I had a skim through the previous pages but may have missed something.
    Thanks!
    Joe
     
  37. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    Hey Joe,

    I don't think this has been answered before. You could just start the movement as usual and run your own coroutine that calls ChangeSpeed over time and increase the value you are passing in. A similar implementation is used for the "rapid input" vehicle sample scene, where the vehicle speed decreases over time.
     
  38. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    511
    if i have a 2d rigidbody following a path and i apply a force to the rigidbody, what happens? does it remake the path? is there a performance drop because a 2d rigidbody is moved along a path using translations?
     
  39. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    Your object will most likely rotate around itself while staying on the path. DOTween moves the transform along the path, not the rigidbody, so that's not really related to each other.
     
  40. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    511
    how do other people integrate rigidbody physics with tweening? Is it even possible?
     
  41. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    A tween animates your object on the path - and only there. Like a playback. If you want to apply forces to the object, you have to either pause the tweening routine, or only apply the force to a child of it so it doesn't affect the main object with the movement script. In this case you can do whatever you want with the child object, while its parent still moves on the path and affects the child too.
     
  42. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    511
    i see i see thanks.

    I assume pausing the tweening on collision won't work since the force was already applied before the tweening was paused, right?
     
  43. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    Good question, I haven't tried that out before. Maybe you could save the force on impact, pause the routine, then apply the force. Or use a raycast to pause the tween before it hits something.
     
  44. luniac

    luniac

    Joined:
    Jan 12, 2011
    Posts:
    511
    nice suggestion , thanks.

    I guess for simple examples i can just onCollision turn off tweening. set isKinematic to false, and apply some force then.
     
  45. louis_k

    louis_k

    Joined:
    Mar 10, 2015
    Posts:
    3
    Good day Baroni

    First, I'd like to thank you and congratulate you for the great work,
    great library

    I am a newbie to Unity and SWS, and I am having a problem with SWS, I am trying to make a game similar to TempleRun and Subway Surfers

    The idea is that there are 3 parallel paths (with some curves) and I want to be able to move the character from one path to another

    something similar to this:




    I have tried many solutions with out success

    1. I tried to use the setPath() function,

    Code (CSharp):
    1.     void Start () {
    2.         spline = GetComponent<splineMove>();
    3.     }
    4.  
    5.     void Update () {
    6.         if(inRightPath)
    7.             if(Input.GetKeyDown("left"))
    8.                 spline.SetPath(WaypointManager.Paths["midPath"]);  
    9.     }
    but it makes the character go the Start of the target path (midPath for example)

    2. I tried to modify the method setPath() and add one more argument which is desiredPoint

    in setPath:

    Code (CSharp):
    1.    
    2. public void SetPath(PathManager newPath, int desiredPoint)
    3.         {
    4.              currentPoint = desiredPoint;
    5.  
    6.  

    and that's how I called it:
    Code (CSharp):
    1.     void Start () {
    2.         spline = GetComponent<splineMove>();
    3.     }
    4.  
    5.     void Update () {
    6.         if(inRightPath)
    7.             if(Input.GetKeyDown("left"))
    8.                 spline.SetPath(WaypointManager.Paths["midPath"], 3);    
    9.     }
    but the problem I faced was that the character moves to the wayPoint, which is not quit what I want.

    I want to move to the other path with +2 in the forward axis, weather there is a wayPoint or not,

    Can I do that in SWS? what do I need to modify?

    Thank you and sorry for the long question :/

    Any suggestions, advice, or comment is much appreciated
     
  46. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    Hi louis,

    thanks for the kind words and very detailed explanation! Makes it easier to help you out.

    Unfortunately there is no reeeeeally easy way to move from one waypoint (let's say on path1) to another waypoint on path2. Basically you would have to stop the movement, set the startPoint variable and path for path2, enable moveToPath and watch the magic happen (or... not, as you've tried already).

    What's much more controllable and battle-tested is to only create one path, in the middle of your road. Then you would create an empty gameobject, attach the movement script to it and check "local". Make your character a child of this new gameobject. Now when the tween runs, you can modify the local position of your character (child) independent from the tween. This means you can move the child +2 left, for example, while the main object still follows the path. Another user has made exactly that, here: link.
     
  47. louis_k

    louis_k

    Joined:
    Mar 10, 2015
    Posts:
    3
    Thanks for the fast reply,

    I got your idea

    I will work on it and let you know what happened

    Thanks again
     
  48. jeffries7

    jeffries7

    Joined:
    Jun 25, 2014
    Posts:
    39
    Unfortunately Unity forums don't offer a way to search specific threads, so my apologies if this has already been asked and answered. My question is, does this allow the way points to be moved and added/deleted at runtime, resulting in the curve being updated?
     
  49. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,306
    Hey jeffries,

    for the most part, no. Tweens are like animations and cannot be updated at runtime, while they are playing. If you would like to update a path, this has to happen while no object is moving on it. An exception is the movement script using Unity's pathfinding system (NavMesh Agents), which calculates the target position in every frame.
     
  50. jeffries7

    jeffries7

    Joined:
    Jun 25, 2014
    Posts:
    39
    Thank you for the quick reply. I see with the Advanced -> local demo that the path is moving. I would assume I can modify that you account for the new positions?
     
unityunity