Search Unity

Simple Waypoint System (SWS) - Move objects along paths

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

  1. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    The tween moving your object (splineMove.tween) has an ElapsedPercentage property, which returns the percentage where your object is currently positioned on the path. This will return the percentage on the full path, not between waypoints. If you need to figure out to which waypoint your object is moving to, you can read the currentPoint variable.
     
  2. StickFigs

    StickFigs

    Joined:
    Apr 3, 2014
    Posts:
    23
    Right but even with the knowledge of the entire path length, percentage, current point, and next point it isn't enough. I need to at least know the length of each segment between waypoints then I could calculate the number I want.
     
  3. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @Izitmee any idea on how to get that data?
     
  4. StickFigs

    StickFigs

    Joined:
    Apr 3, 2014
    Posts:
    23
    If it's any help, I found that DOTween's Path.cs class here does actually store the length of each waypoint segment here:

    https://github.com/Demigiant/dotwee...bly/DOTween/Plugins/Core/PathCore/Path.cs#L28

    Code (CSharp):
    1. [SerializeField] internal float[] wpLengths; // Unit length of each waypoint
    This is actually used to trigger "waypoint changed" events as seen here:

    https://github.com/Demigiant/dotwee...n.Assembly/DOTween/Plugins/PathPlugin.cs#L118

    Which I'm assuming SWS uses in their own "waypoint reached" event system.
     
  5. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @StickFigs speaking of events and segments, you could get the time needed for a segment by placing your object to a waypoint using tween.GotoWaypoint(0, false) and calling tween.Elapsed(). This will return the time needed for moving to waypoint 0 (which should be 0). Then call tween.GotoWaypoint(1, false), call tween.Elapsed() again and substract the time value of the previous waypoint. Now you have the time value for this segment.

    Back to your initial question - how to let an object reach the desired rotation before reaching the next waypoint - you could use this time value for your rotation lerp. Started via an event at a waypoint, for example.
     
    Xriuk likes this.
  6. StickFigs

    StickFigs

    Joined:
    Apr 3, 2014
    Posts:
    23
    That sounds like it would work but the time interval would need to be recalculated if I adjust the speed of the spline mover or change it's motion via easing functions, or interrupting its movement mid-segment. Also I wouldn't be able to modify the path without needing to recalculate the number too.

    The ideal situation would still be to lerp on a percentage of the distance between points but it's becoming increasingly obvious that this isn't an easy value to get. :(
     
  7. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    In the case of speed and easing changes only. Pausing the tween does not have any effect on the time value.

    As with changes to easing, path changes will require restarting the tween. So you would have to recalculate it anyway.

    It's not easy, but certainly possible to implement custom rotations on top of the running tween. I don't know your exact requirements for that, so it could be necessary to get in touch with the developer of DOTween directly to request a new method.
     
  8. StickFigs

    StickFigs

    Joined:
    Apr 3, 2014
    Posts:
    23
    Right, looking at the DOTween source I can see that this information isn't accessible without modifying the DOTween source so it would be outside the possibility of SWS to achieve this alone.

    Thanks for the help though!
     
  9. StickFigs

    StickFigs

    Joined:
    Apr 3, 2014
    Posts:
    23
    Hello, I'm back!

    I have a new issue...

    I created a path in Unity, then I dragged the parent of the waypoints, the one with the PathManager script, into my assets folder to create a prefab.

    Then I attached a splineMove script to a cube and dragged and dropped the Path prefab into the Path Container property field of the splineMove script.

    I am getting strange behavior where when the tween starts it appears that the path is being instantiated at the origin of the world rather than the cube following the path relative to its current position like I expected. The cube jumps to wherever it is all the way to the first waypoint near the origin.

    Does SWS not support path tweens being dynamically added and run during runtime?
     
  10. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Hi, it does. The runtime scene has a sample for instantiating a path + movement object. If you instantiate paths at runtime, make sure to call SetPath(PathManager) on the movement object instead of assigning the path prefab directly.
     
  11. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Thanks for great asset, I have added one functionality to it (Idk if already present) , I have added one UnityEvent under splineMove' OnWaypointChange() ,It will get call on every waypoint player reaches,so its usefulness will be to have one event call on all waypoints,something like for speed change at every junction .
     
  12. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    163
    Hi I'm having some issues with object orientation on complex paths.

    Im sending multiple objects each with there own DOPath along the same waypoint path using DoPaths's .fullPosition.

    I want the behaviour whereby all objects that pass a certain point on the path to be facing the same direction at that point, however over time the objects take on new orientations and point various ways, see in in the below video.



    Any ideas about why this behaviour is happening?

    Thanks

    Here's my code:
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections.Generic;
    4. using DG.Tweening;
    5. using SWS;
    6.  
    7. public class TweenGroup : MonoBehaviour
    8. {
    9.     //public PathManager pathMan;
    10.     public PathType pathType = PathType.CatmullRom;
    11.     public bool closeWaypointLoop;
    12.     public Transform prefab;
    13.     public int noOfObs;
    14.     public Vector2 randomScale;
    15.     public float speed;
    16.  
    17.     private Vector3[] waypoints;
    18.     private float timeValue;
    19.     private Tween t;
    20.     private List<Transform> prefabPool = new List<Transform>();
    21.     private List<Tween> tList = new List<Tween>();
    22.  
    23.     void Start()
    24.     {  
    25.         BuildObs();
    26.     }
    27.    
    28.     void Update()
    29.     {
    30.         MoveGroupAlongPaths();
    31.     }
    32.    
    33.     void BuildObs()
    34.     {  
    35.         PathManager pathMan = this.gameObject.GetComponent<PathManager>();
    36.         waypoints = pathMan.GetPathPoints();
    37.  
    38.         for ( int i = 0; i < noOfObs; i++)
    39.         {  
    40.             Transform prefabOb = Instantiate(prefab, waypoints[0], Quaternion.identity) as Transform;
    41.             prefabOb.transform.parent = this.transform;
    42.             float theRandomScale = Random.Range (randomScale.x,randomScale.y);
    43.             prefabOb.transform.localScale = new Vector3(theRandomScale,theRandomScale,theRandomScale);
    44.             prefabPool.Add(prefabOb); // prefab pool is uneccessary but might be useful for later on in the programming
    45.  
    46.             t = prefabOb.DOPath(waypoints, 1, pathType) //set it to 1 so it will take a second to complete
    47.                 .SetOptions(closeWaypointLoop) // this closes the loop and lets it become loopable
    48.                 .SetLookAt(0.0f); // this is how far for the object to loko ahead to turn, smaller numbers sharper turns
    49.             t.SetEase(Ease.Linear).SetLoops(-1);
    50.             t.Pause();
    51.             tList.Add(t);
    52.         }
    53.     }
    54.  
    55.     void MoveGroupAlongPaths()
    56.     {
    57.         for ( int i = 0; i < tList.Count; i++ )
    58.         {  
    59.             float basePercent = i * (1.0f / tList.Count);
    60.             float finalPercent = (basePercent + timeValue);// % 1.0f; // loop over 0-1 range
    61.             //Debug.Log (finalPercent);
    62.             t = tList[i];
    63.             t.fullPosition = finalPercent;
    64.         }
    65.         timeValue += Time.deltaTime * speed;
    66.     }
    67. }
     
  13. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    I'm not sure, but it sounds like that's the same functionality as using the events section on the movement script.

    Hi wxxhrt, since you're using your own movement script and only custom DOTween settings (besides having a PathManager for the waypoints), your question would be better directed at the developer of DOTween.
     
  14. wxxhrt

    wxxhrt

    Joined:
    Mar 18, 2014
    Posts:
    163
    Ok thanks, will post over there :)
     
  15. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    @Baroni You mean that splineMove's events which get trigger on each waypoint? with that approach same event must be drag-drop on each event call,
     
  16. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    @Baroni Hi,I have one question ,How can I show rank of players on racing game ? How to calculate rank?
     
  17. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    What rank? How does Simple Waypoint System come in handy with that?
     
  18. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Suppose I am using simple waypoint system in racing game.So I will have multiple enemy bots say 5.Now total players including user will be 6.

    So it will be useful to get rank of player out of those 6 according to his/her position on race track.

    **EDIT** Just seen elapsed percentage property which can be used for getting rank of player.Though suppose we have multiple paths then it becomes quite tedious to calculate rank of players

    **EDIT 2** Solved it by adding trigger at end of first path which will increase elapsed percentage by +1 ,so on next path elapsed percentage will be , elapsedPer + 1 and so on.

    Now I am having weird problem,have look at following img,
    http://imgur.com/utE09UR




    First time when I create path it was straight line as expected,after editing waypoints position it start to occure
     
    Last edited: Sep 6, 2015
  19. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    I'm not sure why that is happening because DOTween does all the path calculation stuff, but it is more likely to happen if you have waypoints very close to each other or the scale of your game is too small. Bezier paths give more control on the shape of your path and also allow to choose the amount of intermediate points on segments (for path/curve detail).
     
  20. Shirts

    Shirts

    Joined:
    Nov 4, 2012
    Posts:
    8
    Dumb question:

    On any single key press, I want to move the object, over time, to the next waypoint (a specific waypoint in the path). How would I do that? Not progress, or holding a key down, but on a single press.

    thanks.
     
  21. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    @Baroni ok wil look at bezier curve, how much will performance suffer if used bezier for android?

    @Shirts I think you can use "GoToWaypoint" method for your particular problem...
     
  22. Shirts

    Shirts

    Joined:
    Nov 4, 2012
    Posts:
    8
    Hmm, maybe I was running an older version because I didn't see that option.

    thank you.
     
    idurvesh likes this.
  23. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @idurvesh the performance impact should not be noticeable at runtime, as the initialization of the path requires the most resources - after that it's just moving like on any other path.
    @Shirts this should be what you're looking for. GoToWaypoint only teleports objects to a waypoint.
     
    idurvesh likes this.
  24. Shirts

    Shirts

    Joined:
    Nov 4, 2012
    Posts:
    8
    Thanks for
    Thanks for your response. That seems exactly what I'm looking for. I will try that today. Cheers to the speedy response. I don't know how you keep up with all the questions. :)
     
  25. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Vacation, motivation and beer :D
     
    idurvesh likes this.
  26. bakershah

    bakershah

    Joined:
    Jul 15, 2014
    Posts:
    17
    I'm having trouble selecting the waypoint manager when creating a new pathpoint. When I go to select a name for the waypoint path it doesn't select it. not sure what the problem is but any help would be appreciated.
     
  27. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    @Baroni yes trying bezier curve do giving proper path yet it seems like time consuming, here are more details,
    When we create path with "standard" option, the catmull path generates curves auto on curvey path whereas in bezier it gives us straight line so we have to manually edit it and make curve.

    So I think having one option like, bezier curves will also generate curves like standard one and latr we can change as per requirement
     
  28. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @bakershah please update to the latest version. There has been a bug in Unity 5.1 which prevents entering a path name.

    @idurvesh having full control over the bezier curve is actually the desired behavior, because it needs two additional control points per waypoint which have to be adjusted manually. Auto-aligning these would go against this purpose.
     
  29. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    yes that's right, yet I think instead of having straight lines on curves, auto curve lines would be more useful as that's the purpose most of people uses bezier curve for, it will save alot of time
     
  30. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Right, I'll see if I can get the control points to auto align in the direction of the last waypoint in the future.
     
    idurvesh likes this.
  31. Ultrapp

    Ultrapp

    Joined:
    Aug 12, 2015
    Posts:
    27
    Hello,
    I recently started in the use of this great asset.

    I need to create a "Closed Loop" but the runtime line motion moved too .... and my fish flying!!!
    I tried various combinations featuring "SplineMove" script and the movement and displacement are allocated.
    I also need to have marked the "Local" option, if I don't do the fish does not appear in the scene.

    Any help please?

    I leave a video with the problem.

    https://drive.google.com/file/d/0B8YNgQXSI8KIRzVib0VPRURRTnc/view?usp=sharing

    Ariel T. M.
     
  32. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @Arieltm Hi there, thanks for using SWS and for the video! Please contact me via one channel only (not on both forums).
    You have to parent your fish gameobject to the path, as seen in the example scene "advanced" - have a look at the local sample with the rotating path. You may also want to consider rotating your fish sprite by 90 degrees to face the path direction, using an intermediate gameobject.
     
  33. mog-mog-mog

    mog-mog-mog

    Joined:
    Feb 12, 2014
    Posts:
    266
    Can I change the tweening to LeanTween?
    DOTween keep giving warnings
    Avoiding invalid array index access.
    I believe some script is not cancelling the tween when object is destroyed. It is closed dll, so I cannot even comment that warning. It doesn't effect gameplay, everything works perfectly. but it prints warning in every frame which spams log file.
    My dotween preference is log only errors.
     
  34. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @lilboylost You would have to write your own movement scripts for that, as I do not support LeanTween. Please do post the error message here so I can discuss it with the developer of DOTween.
     
  35. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    Hi! Earlier I told about this problem, that has occured again.



    Now I noticed the reason for it. If the gameobject has a Rigidbody component "the twist" appears.

    You can try this by making a SWS path, then make for example a Cube and make it go Loop with Close Loop (using Spline Move script). This works. Now add rigidbody to the Cube and this twist appears to the path.
     
    Last edited: Sep 16, 2015
  36. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @Nadan are you using gravity on the rigidbody? I'm not in the office for the next week, I'll have a look at it when I'm back.
     
  37. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    Yes I did, but it does the same 'Use Gravity' checked off.
     
  38. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    @Baroni Yes thats the same problem I was talking about and occurring to me which
    @Nadan is pointing out ...


    also one more problem I am facing as follows,
    my path has downward slop, so when character moves into downward slop, the character and camera keep looking at forward direction instead I want it to look to down as per path...any idea how to accomplish it?
     
  39. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @idurvesh have a look at the path orientation and rotation lock variables. By default the objects follows the path orientation exactly, so you must be using some rotation locking.
     
  40. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Yes rightly said so, I am locking X rotation and removing that do work properly, but hey without X lock while moving doward-curves my character controller falls at its side....I tried box and capsule colliders none working...
     
  41. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    Hi! Another question. In my game there are moving platforms that rotate/tilt.

    So I placed the Waypoint Manager and the Path Manager with the nodes as a child for this rotating platform. When the platform rotates in the scene view also the path nodes (waypoints) rotate like I need them to do. But when I play the game the path nodes seems to move in the Scene view but it seems it's still "locked" in the original path position that it was at the beginning before the platform rotated.

    Is it possible that the path nodes would change their places, in this case rotate and make the object/character dynamically go to these new changed positions?
     
  42. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @idurvesh
    Colliders don't have anything to do with rotations? Could you please send me an email with a repro project to check out when I'm back (next weekend).

    @Nadan
    It doesn't work like that - DOTween expects coordinates around the origin of the scene, i.e. world positions. If you are using local tweens, check the advanced sample scene (scene 4). There is a rotating path with a local moving object attached to it - not the other way around.
     
    idurvesh likes this.
  43. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    I checked the sample scene 4 and this is what I'm looking for. if I just added the same movement to the path as I do to the platform I think it would work.

    But what is local tween? How do I make the same thing as in the scene 4?
     
  44. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    Local tweens consider local positions instead of world positions. Make your moving object a child of the path, tick the "local" checkbox on the movement script and rotate/move the path around as you like. The moving child will follow.
     
  45. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Thanks, PM you link to my project,plz have a look in soon
     
  46. Nadan

    Nadan

    Joined:
    Jan 20, 2013
    Posts:
    341
    Got it. Now it's working as planned. Thank you!
     
    Last edited: Sep 20, 2015
  47. deekpyro

    deekpyro

    Joined:
    Oct 16, 2012
    Posts:
    71
    Hey Baroni - I'm trying SWS with our game and I like the path editor. In regards to how SWS handles rotation though a tweening object faces forward on the path rather than using the rotations of the transforms. What's the best way to rotate the tweening object in this way?

    Thanks!
     
  48. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,260
    @deekpyro
    Hi, you mean the rotations of the waypoints? In that case there is no setting to do that currently, so you could disable the path orientation completely (set path mode to none) and write your own coroutine which rotates the object to the next waypoint over time, by using waypoint events for example.
     
  49. deekpyro

    deekpyro

    Joined:
    Oct 16, 2012
    Posts:
    71
    Okay, I'll give that a try.
     
  50. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Sent PM bro have you got it?