Search Unity

Simple Waypoint System (SWS) - Move objects along paths

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

  1. MornFall

    MornFall

    Joined:
    Jan 11, 2013
    Posts:
    160
    Thanks ! you are awesome.
     
  2. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    Hi!

    I have some problems with Standard paths. I try to close the loop by selecting "Close Loop" in the "Spline Move" script. But I it always makes this twist around and the character rapidly moves back and forth. Is this know issue? Am I doing something wrong? All the help would be welcome.

     
  3. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    CCing @Izitmee as DOTween calculates all the path stuff. Which version of SWS and DOTween do you use?
     
  4. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    I was using v5.0.2 of SWS, now I updated it to v5.0.4 but I still have the same problem . Where can I see the version of DOTween? The DOTween folder only has a readme file but I didn't find any info there.
     
  5. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @Nadan Tools > DOTween Utility Panel. Should be the newest in latest version though.
     
  6. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    Ok, its V1.0.720. It seems that the latest version is V1.0.770. So I quess I should try to update it as well.
     
  7. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    Ok, I updated to V1.0.770 but the problem remains.
     
  8. CronoCaracas

    CronoCaracas

    Joined:
    Apr 23, 2015
    Posts:
    3
    @Baroni

    Thank you very much! Is amazing to find such disposition to help others in members of this community like you :)
    I will get to it and later I will let you know how it worked. Please, continue your amazing job (y)
     
  9. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    I updated my Unity to 5.1.1f1 and the problem went away.
     
  10. MornFall

    MornFall

    Joined:
    Jan 11, 2013
    Posts:
    160
    @Baroni

    Sorry but i shouted victory too soon...

    I replaced the mover.Pause() by Stop, then i put moveToPath = true, and call StartPath.
    The issue is that now they go back to the first waypoint, instead of going back to the currentwaypoint.

    After having a closer look at SplineMove, the Stop() reset the currentPoint to 0. Are you certain that i need to call Stop then StartMove to go back to the currentPoint and resume the path ?
     
  11. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    currentPoint does not get resetted anymore since version 5 I think. Are you still using the older, HOTween compatible version? The new version using DOTween has a performance boost for up to 400% too.

    Edit: Optionally, if that doesn't work out, you can also play with the startPoint variable (latest version) like this:
    Code (csharp):
    1. //cache latest waypoint before stopping
    2. int currentIndex = yourMoveScript.currentPoint;
    3. yourMoveScript.Stop();
    4.  
    5. //do your stuff - chase player etc.
    6.  
    7. //continue where it left off
    8. yourMoveScript.startPoint = currentIndex;
    9. yourMoveScript.moveToPath = true;
    10. yourMoveScript.StartMove();
     
    Last edited: Jun 22, 2015
  12. HappySlice

    HappySlice

    Joined:
    Nov 3, 2014
    Posts:
    22
    It seems that having a rigidbody/collider makes everything wonky. I put the rigidbody in an empty gameobject and made that gameobject move along the path, but the rigidbody slowly deviates from the center of that gameobject. I turned the gravity off, but I need a collider so the player can shoot it.
    Has anyone else run into this problem?
     
  13. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    I've also had problems with rigidbody, animator, colliders and gravity after I updated Unity. Anyway, did you try setting rigidbody to IsKinematic?
     
  14. MornFall

    MornFall

    Joined:
    Jan 11, 2013
    Posts:
    160

    Thanks ! Your optionnal setup did the trick. I am not sure why the point gets resetted with the first method, i made sure i got the latest version and re-work my mover.cs from splineMove.cs...
    Anyways, it s working now.
    Although, it is not perfect. my "Swarmer" Rotates immediately, not smoothly, when it gets back to its currentPoint. But i guess that is something i will have to tweak on my mover.cs myself. :)
    Thanks for your help !
     
  15. HappySlice

    HappySlice

    Joined:
    Nov 3, 2014
    Posts:
    22
    Yes, but I need bullets to collide with the object
     
  16. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Collisions or trigger messages are being sent correctly if certain conditions are met. The collision matrix on this page should still be valid.
     
  17. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    I've noticed that the rotation of the waypoint object doesn't affect the walker rotation. Is there a way that the walker not only moves toward the next waypoint but also slowly change its rotation to match the rotation of the waypoint when it reaches it?

    Thanks in advance
     
  18. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    There's the path mode dropdown, which let's your walker rotate to the path orientation, or you could disable rotation completely and attach your own rotation script to the moving object - you have access to all waypoints of a path and could do that in a rotation lerp method, for example. I can see that matching the waypoint rotation along the path could be useful for setting up cinematic things like camera movement, but haven't done serious development on that area yet. Or as Unity would say it, it's in research.
     
    SVC-Games likes this.
  19. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    Well at least I can mess freely with the object rotation withouth altering the path. But as you said it would be a really nice feature :)
     
  20. Freeubi

    Freeubi

    Joined:
    May 30, 2014
    Posts:
    21
    Hellp,

    Can i move the paths on runtime, with a mother gameobject (gameobject with parented paths)?
    I have a paralax background and i want to move with them.
     
  21. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Yes, you can move paths with the moving object on them. Only moving the path usually doesn't work, because moving objects can't update to the new path position unless you restart their movement from the beginning. If you already own SWS, there's the local sample in the advanced example scene for that.
     
  22. ProtoJazz

    ProtoJazz

    Joined:
    Nov 27, 2012
    Posts:
    19
    Im having a strange issues. Every once in a while (maybe about ever 1/50?) The OnWaypointChange doesnt fire for the last waypoint on the path. I have an event thats supposed to fire when the character reaches the end of the path (for example walking to a chair and then sitting down once they are there) and for some reason sometimes that last event doesnt fire. Any help would be appreciated.
     
  23. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @ProtoJazz OnWaypointChange is an event fired by DOTween, the movement scripts in SWS just access them. Could you check whether it is related to this issue - which inserts an additional waypoint at the beginning, potentially caused on looping paths. If possible, please send me a project that reproduces this to my email (last page in documentation pdf).

    @Izitmee maybe related to our private bug conversation
     
  24. ProtoJazz

    ProtoJazz

    Joined:
    Nov 27, 2012
    Posts:
    19
    @Baroni

    They are not looping paths. I can try to pack up a project and send it to you sometime this weekend


    EDIT :
    Crap, Im an idiot. Its totally my fault, not SWS or DOTween.

    For reference what I was doing :
    In my project I have a bunch of characters that play animations when you click a button, basically an interactive storybook. So I wanted the characters to walk to a part of the room, then do something when they got there (Walk to chair -> sit in chair)

    So I was just adding an event to the end of the list of events. But I wasnt resetting the events list in my spline move script. And I wasnt testing it properly when I came to the conclusion the event wasnt firing. What my tests DID show was that the LAST index was never being reached in the index list, but that was because Id changed the size of the list to be bigger than the index would go. Like it would become 4 if there were 4 waypoints, then stay at 4 for a 3 waypoint path.

    Totally my bad, I just reset the list now and it works. I also found the ReachedEnd event, which also does exactly what I wanted.
     
    Last edited: Jul 19, 2015
  25. SangHoang

    SangHoang

    Joined:
    Jul 7, 2015
    Posts:
    3
    i try add to some game object (use Spline Move),so DOTweenComponent.Update() very hight CPU usage. ~ 71%. some one help me. thanks all
     

    Attached Files:

    • demo.PNG
      demo.PNG
      File size:
      97.8 KB
      Views:
      916
  26. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @ProtoJazz thanks for clarifying! It's correct that the event list isn't cleared automatically, so for example you could keep an event at waypoint 4, switch to a path with only 3 waypoints, and going back to the old path with the event at waypoint 4. In other cases, resetting is the way to go.

    @SangHoang 71% of what? Could you post the profiler screenshot with the method (Deep Profile enabled)?

    Edit: Please enable Deep Profile and extend the DOTweenComponent.Update() method to where it actually takes up the most performance. Also please tell me your setup - how many movement scripts are in the scene?
     
    Last edited: Jul 19, 2015
  27. SangHoang

    SangHoang

    Joined:
    Jul 7, 2015
    Posts:
    3
    i used 5 movement script in my scene, dowloaded this package from asset store then i add DOTweenPro, i remove DOTween in SWS forder
     

    Attached Files:

    • demo.PNG
      demo.PNG
      File size:
      235.2 KB
      Views:
      850
  28. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @SangHoang Thanks. Two things:
    1. You have a polygon collider and a box collider on the same object. Unity's Physics2D engine wants to recreate both of them whenever their position changes. If possible, try to use one of them, not both.
    2. In your profiler screenshot, I can see that you are calling DOLocalMoveY from somewhere. I've checked and this method is not used by splineMove at all. splineMove uses DOPath or DOLocalPath only. You must be doing some other tweens too. As a comparison, my profiler looks like this with 5 splineMove objects.
     

    Attached Files:

  29. SangHoang

    SangHoang

    Joined:
    Jul 7, 2015
    Posts:
    3
    oh, my bad. i called DoLocalMoveY in update from somewhere. thanks for your help
     
  30. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    Hi, I have a path where the character walks stairs up and down.



    How can I make the character face up? As you see in this pic the character in the stairs has turned about 40 degrees.
     
  31. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Hi, set the "Lock Rotation" variable on the movement script to X.
     
  32. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    Working! Thanks.
     
  33. hensoup

    hensoup

    Joined:
    Jan 13, 2014
    Posts:
    35
    trying to figure out doing a god of war camera system where the character moves independently alone the level and the camera follows the player along the path the camera is set on like it's folowing by rail. I'm trying to get it when the player moves left or right or foward or back the camera moves aloung the trail and follows the player in it's own way point trail
     
  34. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    You can set the progress of a tween manually and if the player moves forward, increase the progress of the camera tween to let it follow. The tween has be initialized once, after that you can pause the movement script and modify it directly. The path input demo scene has a sample on how to do that, as the same approach is used for placing the player on the path.
     
  35. hensoup

    hensoup

    Joined:
    Jan 13, 2014
    Posts:
    35
    I see what you mean I tried doing a back object and forward object the reason I asked this is the game is full 3D movement but if theres a way to do Full 3D movement on a path for just the camera basing on location than I'll need to just figure out where this will work
     
  36. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    I'm not sure if I got that part. Paths are in 3D and the sample scene I've referred to, too. Setting the progress value of a tween should actually work very well for Sonic runner games and the like. If you want to always keep the camera behind the player at a fixed distance instead, tweens are not designed for that.
     
  37. hensoup

    hensoup

    Joined:
    Jan 13, 2014
    Posts:
    35
    I agree now that I figured it/ THOUGH I must say this system is amazing but I ment the character to move around up down left right and jump and duck while the camera follows the character while strictly thru the path of waypoints simular to devil may cry and god of war.
     
    Last edited: Jul 24, 2015
  38. latas

    latas

    Joined:
    Oct 9, 2013
    Posts:
    149
    Hello,

    I just bought this fantastic plugin, but I need some help with the settings in my game.

    I need to make enemies follow a path (with the plugin is easy as pie with spline movement), but my path is not regular like a plane, it is a terrain with areas at different height.
    Those enemies are rigidbodys so they are should be affected by gravity, but my problem starts here, when I use SWS to follow an irregular path, the rigidbodys sometimes do strange movements and the biggest problem is that they "fly" when have to go to another waypoint with different height.

    I think it is because the plugin moves the transform so the rigidbody stop being affected by gravity, but how can avoid that to have a more realistic movement across the path?

    Thanks!
     
  39. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Hi latas,
    splineMove utilizes DOTween as the underlying tweening library. Tweens move your object on a fixed path, like an animation, and are not designed to recognize the scenery (physics, terrain heights). How about using Unity's navigation system with navMove instead?
     
  40. VectorNector

    VectorNector

    Joined:
    May 22, 2013
    Posts:
    62
  41. VectorNector

    VectorNector

    Joined:
    May 22, 2013
    Posts:
    62
    Nevermind, I found it in the example scenes. Thought I had to write and event or something.
     
  42. gozdagb

    gozdagb

    Joined:
    Feb 23, 2014
    Posts:
    71
    Hi
    Is possible to make collisions between other objects and pushing him out of path?
     
  43. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @gozdagb Hi, colliders with rigidbodies should work.
     
  44. soldier11213048

    soldier11213048

    Joined:
    Mar 29, 2015
    Posts:
    11
    I can't input data whene use EditorGUILayout.TextField in Unity 5.1.2f1 But it can work in Unity 5.0.1f3. Thes code is :

    pathName = EditorGUILayout.TextField(pathName, GUILayout.Height(15));

    result is

     
  45. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    This has been fixed back in July (SWS version 5.0.4).
     
  46. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    163
    I'm trying to make a group of objects move along a looped path in unison one after the other all on the screen at the same time as in the attached image




    I've implemented this in iTween but don't like iTween's waypoint manipulation system and was hoping I could get it up an running using SWS. In iTween I used a function to place each object at a certain percentage along the path and another function to orient the objects to the path. Are these functions available using SWS? Thanks
     
  47. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Yes. SWS uses DOTween as the tweening library, and by accessing the tween you can manipulate its tween.fullPosition or rotation - the latter can also be set directly in the inspector.
     
  48. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    163
    Thanks, I've bodged something together using the example on the DOTween website :

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using DG.Tweening;
    4.  
    5. public class Paths : MonoBehaviour
    6. {
    7.     public Transform target;
    8.     public PathType pathType = PathType.CatmullRom;
    9.     public Vector3[] waypoints = new[] {
    10.         new Vector3(4, 2, 6),
    11.         new Vector3(8, 6, 14),
    12.         new Vector3(4, 6, 14),
    13.         new Vector3(0, 6, 6),
    14.         new Vector3(-3, 0, 0)
    15.     };
    16.     public float timeValue ;
    17.     private Tween t;
    18.  
    19.     void Start()
    20.     {
    21.         // Create a path tween using the given pathType, Linear or CatmullRom (curved).
    22.         // Use SetOptions to close the path
    23.         // and SetLookAt to make the target orient to the path itself
    24.         t = target.DOPath(waypoints, 1, pathType) //set it to 1 so it will take a second to complete
    25.             .SetOptions(true)
    26.             .SetLookAt(0.001f);
    27.         // Then set the ease to Linear and use infinite loops
    28.         t.SetEase(Ease.Linear).SetLoops(-1);
    29.         t.Pause();
    30.  
    31.  
    32.     }
    33.  
    34.     void Update()
    35.     {
    36.         t.fullPosition = timeValue; // as the tweens time length is 1 then a timeValue of 0-1 moves along whole loop
    37.     }
    38. }
    I'd like to be able to access the waypoint I've drawn in SWS from this script, rather than typing one in by hand- is that possible? Thanks
     
  49. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Yes, the PathManagers in SWS provide access to each waypoint and you can also set the path per movement script by its (path) name.
     
  50. StickFigs

    StickFigs

    Joined:
    Apr 3, 2014
    Posts:
    23
    I am looking to write my own script that I could attach to the gameObject which is following a path to make it rotate X degrees starting at waypoint A and finishing at B. Is there a way I could get a value from the splineMove which represents the percentage of the way between it's last and next waypoint are so I can lerp the rotation to start perfectly at A and finish at B?

    And I want to get the percentage as it pertains to the curve between the waypoints, not just the approximate position on a straight line between A and B.

    EDIT: It looks like this would be impossible without modifying the SWS source.
     
    Last edited: Aug 26, 2015