Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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,256
    And I've posted a possible way of implementing it back here, which sounds similar to the approach you did. Depending on the setup, simply changing the speed to a negative value (by calling ChangeSpeed() on the movement script) could work too. I agree that the advanced "reverse functionality" should be a method built in.
     
  2. MarcopoloR

    MarcopoloR

    Joined:
    Feb 4, 2015
    Posts:
    114
    Thanks, I did go into gizmos before but I guess I clicked the wrong ones, I didn't look to see there were a lot more to click, but I finally found the right ones, thanks. I still don't know why it is doing this where it wasn't before.
     
  3. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    515
    Sounds easier ) Didn't ever though such method exist
     
  4. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    515
    Baroni sorry, but I got 1 more question about events.
    In some cases Event triggered exactly on the bezier point reaching, but sometimes that trigger earlier.
    Here is an example:
    I tried to set Event on WayPoint3, but that trigger on the small point before it.
    Tried both ways - using inspector, and by the script
    Code (CSharp):
    1. bezierMove.events[bezierMove.events.Count - 1].AddListener(() => Action());
    Why that happens?
     
  5. josemauriciob

    josemauriciob

    Joined:
    Mar 5, 2009
    Posts:
    662
    is there a DUMMIEST tutorial from cero, to USE and ADDONS or plug-ing - this awesome unity store pack ?
    specialy for unity5x and instantiate any prefab on any path created ?

    thanks a lot .
    .
    dumiest.jpg
     
  6. alex_hajdu

    alex_hajdu

    Joined:
    Nov 10, 2013
    Posts:
    32
    Hello, just quick question before the buy. It's possible to move RigidBody? I'm working on elevator system where I'm using Rigidbody.MovePosition() on kinematic RigidBody. I need to do this in Fixed Update. You mentioned you are using DoTweener and there is possibility to choose between types of updates so I assume yes, but I'm rather asking...
     
  7. Deleted User

    Deleted User

    Guest

    UPDATE:
    -------------------------------------------------------------------------------->>
    Package Broken...
    Brand New Project - Just your asset - Android Build:

    Spline Move example: Crash/Freeze Massive Memory Leak!!
    Taking over 1GB in Ram...Will NOT dispose of [DOTween] Instance.
    ----------------------------------------------------------------------------------->>

    Please look into how this became unusable...please



    After upgrading from 4.6, my android game started freezing the editor, after I play (Game would play, but would freeze) = - Forcing the Unity App to close, was my only option.

    I dumped your folder, and installed the latest version..Same thing.

    I have tracked it down to an instance of DOTween, not being disposed of.(at all - it freezes at that point)..(I see it in the Hierarchy window).

    A) When or how are you destroying that instance.// UPDATE: Found it in SplineMove..
    I will try to force that call..
    Code (CSharp):
    1.         public void Stop()
    2.         {
    3.             StopAllCoroutines();
    4.  
    5.             if (tween != null)
    6.                 tween.Kill();
    7.             tween = null;
    8.         }
    No Paths...runs fine...

    Advice??

    Patrick the Pathless :-(
     
    Last edited by a moderator: Nov 9, 2015
  8. JacobFalling

    JacobFalling

    Joined:
    Apr 27, 2014
    Posts:
    22
    Baroni,

    Thanks for your work creating and maintaining this asset. A lot of good and very manageable functionality here.

    At first, it looked like it would do exactly what I needed for my current project, but now I'm not sure...

    I am building a 2D game primarily using UGui, but the waypoint system seems to lock to world space only. I can make the waypoint manager and its waypoints a child of my 2D canvas/panels, but when the panel is scrolled, the waypoints seem to move along with it, but... that actual paths they produce do not, so my sprite follows the path in reference to the camera, not the parent.

    Any thoughts on how to make this work for me?

    -Jacob
     
  9. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    Hi all, I'm very sorry for the late reply, notifications stopped sending me emails last week.

    @novaVision I have a fix for that in the next update, please send me an email with your invoice number to receive it in advance.
    @JacobFalling to make use of local movement, your object with the movement script needs to be a child of the path with the "local" checkbox ticked. Example scene 4 has a sample for local movement on a rotating path.
     
  10. yandrako

    yandrako

    Joined:
    Dec 2, 2013
    Posts:
    26
    Hi Baroni, first I want to thanks for your great asset.

    After that I have the following doubt-problem:

    My intention is just to have a car that can move along a sws path but with a real spinning wheels (the car from the example scenes of the asset have static wheels). What I have tried so far is use the car from the standards assets (with car controller and car user control scripts) because has all the logic needed to a real simulation (rigidbody, collisions, spinning wheels etc), but the main problem is that now the wheels spins but very unrealistic because the speed value from the SplineMove script (I tried both Time Value = speed and Time Value = time with different values) and the speed from the controllers script from the standard assets never fits.

    Maybe its a way easier to do that, I just want a vehicle that can follow several sws paths at a realistic way (in terms of wheels spinning at an appropiate speed), doesnt need to be the standard assets car (in fact my model is a tricycle).

    Thank you in advance
     
  11. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    Hi @yandrako,

    thanks for your question. Did you try attaching a separate script to the wheels, which accesses the speed variable of the movement script (e.g. splineMove) and rotates it locally based on that? If the speed doesn't match, you could also use a modifier in your script - something like rotationSpeed = speed * 0.6f before applying it to the wheel. This would even work well with speed changes on the car using the ChangeSpeed() method.
     
  12. JacobFalling

    JacobFalling

    Joined:
    Apr 27, 2014
    Posts:
    22
    Baroni,

    Thanks for the direction in a prior post... this and your example scene were very helpful, with two caveats:

    -It's awkward for the object with the movement script must be a child of the path itself for local movement to work. In this case the object is the Player, so I will literally need to reparent my a new path each time it needs to move. Doable, but odd. Perhaps this could be adjusted in a future release.

    -My Player does now follow my test path decently well, but the path itself does not seem to be locked precisely to its object parent (a 2d world map). To make it fit visually, I actually have to adjust and stretch the path a few cm along both axes. This is all actually happening in UGUI canvases, so I'm guessing the problem is less with your tool and more with how the canvases get rendered in runtime, but if there are any thoughts, I'd love to hear it.

    Again, thanks for the great system and great support! Obviously, I'm using this a bit differently than the majority. I'm also working on a couple of 3D games that I can see will use this with no trouble at all. Very simple, but thorough and effective.

    Jacob
     
  13. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    Thanks for your explanation on these things, @JacobFalling!

    Well the reason for the first requirement (parenting) is that Unity just works like that. Obviously to have local movement working, the object needs to consider the local position instead of world positions and has to update on parent changes. With Unity's gameobject oriented approach, parenting makes perfect sense here. Otherwise, one has to store the local offset positions/rotation between the path and walker object on each frame and apply it to the moving object manually. Parenting does this automatically. I don't think that I can work around this in an easy way.

    For your second observation, could you possible send me a screenshot, repro steps or a repro project to my email? I would like to investigate what's going on, if this is something related to SWS.
     
  14. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    515
    Hi Baroni,
    Tell me please, is there a way how check current progress at bezier path?
    I have tried to check it through waypoints and current position, but it is quite complicated way.
     
  15. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    novaVision likes this.
  16. AlexSkylark

    AlexSkylark

    Joined:
    Nov 10, 2015
    Posts:
    6
    Hello.

    I use SWS on a side-scroller shooter, to move a string of enemies along a spline. However, I'm noticing that ON ANDROID (standalone works fine), collision (of shots, for example) simply doesn't work.

    what could cause this type of behavior?
     
  17. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    Hi @AlexSkylark, you are asking the same question in another thread which makes me think that this is something not related to SWS. Could you please reproduce this issue in one of the example scenes with SWS only - in an empty project, no third party assets - and let me know the steps you did.
     
  18. AlexSkylark

    AlexSkylark

    Joined:
    Nov 10, 2015
    Posts:
    6
    OK, some background info is in order then.
    I've been in e-mail contact with the author of the other asset for about a week now, because yes, I first thought the issue was there, since it was related to collision. The thing is, he was able to point me in a direction where I modified some things in that asset, and then it worked - AS LONG AS THE COLLIDER WASN'T IN A PREFAB ATTACHED TO A SPLINEMOVE OBJECT. And as I later investigated the asset's source and noticed it uses a SphereCast() method to detect layer collisions, I wanted to see if this was a known behavior.

    The thing is, if I use "common" collision (just firing a prefab into the ones being moved by SWS) collision works fine, both in standalone and android. And, at the same time, if I fire Xffect particles on stationary or non-SWS-using objects in the scene, it ALSO works fine both in standalone and android (after applying the changes suggested by Xffect's author).

    The sad point is... I *REALLY* need those 2 assets to be able to function together, combined they are the heart of my project. Here's a video of it:



    The different shots are made with Xffect, and the enemy paths are done with SWS. I hope that clarified things a little.
    Thanks again for the attention =) really hope we can get this working... (Actually, I'm depending a lot on it, hahah :D)
     
  19. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @AlexSkylark
    Well if it works without Xeffect, then it's not a bug in SWS (phew!). Could you please send a project that reproduces the issue in the most simplistic way to my email (last page in the documentation pdf). I will try to get to the bottom of this when i have the time - it won't be top priority on my list.
     
  20. AlexSkylark

    AlexSkylark

    Joined:
    Nov 10, 2015
    Posts:
    6
    OK, I am a very ashamed person right now...

    After extensive research and debugging the hell off of my code, building the suggested prototype, and overall banging my head against the problem for WEEKS, trying to explore all places where the collision of either asset might not be working, or where I could have configured object wrongly according to the standard of either asset, even CONSIDERING PORTING THE GAME TO ANOTHER ENGINE... I finally found out what was wrong.

    As you can see, my game is 2D. In a very earlier build, I was using Z-coordinates to sort objects in the scene. After a while I realized that's 100% unnecessary, since we have sprite layers. Then I moved every object to a Z of zero and reworked all the logic,...

    Except one.

    The Movement Logic for the player uses the keyboard arrows (for PC) and the touch interface (for mobile). The touch input works by capturing a touch position and dropping an invisible "anchor" object, an empty GameObject to which the player ship is attracted to whenever it is in the scene. The bug? I was dropping the anchor on Z coordinate +5, the one I was PREVIOUSLY usin as the player position back in the first builds of the game. Of COURSE collision stopped working, the objects were NOT touching each other anymore.

    Well, let this tale of mine be a lesson to all. Working with 2D has it's perks, and... Sometimes the problem is very simple. That was really one of the biggest /facepalm moments of my entire dev carreer. Lolz.

    Sorry about the bothering. I'll show myself out. Hahah.
     
    Burletech and Baroni like this.
  21. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297
    Quick question. How to solve this closed loop issue at the last node.
     

    Attached Files:

  22. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    Insert another waypoint and have the distance between them more consistent.
     
  23. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    297
    But in provided example scene there are only 4 nodes in closed connection and its working fine. only when i create it that issue occurs. Tried all possible ways. Its not creating proper loop. May be i am missing something while creating the path
     
  24. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    The path plugin tries to find the shortest way to the next waypoint. In your case, doing a small turn at the last waypoint is actually faster than walking a perfect (bigger) circle. This is because your last waypoint is a bit "inside" the circle. If you drag it further away (to the south), the turn will go away.
     
  25. txl_muc

    txl_muc

    Joined:
    May 1, 2014
    Posts:
    6
    Hi there,
    I have a quick question regarding the SWS system.
    Is it possible to modify / generate the events-list of the bezierMove script at runtime? I am trying to assign new paths when the application is running, but I couldn't find a way to have the function calls of other game objects added to certain waypoints. Is there a way at all?
    Thanks a lot!
    Felix
     
  26. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    Hi @felix_muc,
    the "runtime" example scene has a sample on how to add events to waypoints when the game is running. It is using splineMove though.
     
  27. txl_muc

    txl_muc

    Joined:
    May 1, 2014
    Posts:
    6
    Thanks for the quick response!
     
  28. txl_muc

    txl_muc

    Joined:
    May 1, 2014
    Posts:
    6
    Hi again,
    still trying to add some events after setting a new path. There's no error message, but the events do not appear in the list inside the editor (bezierMove), and they do not get invoked. Here's the code.

    Code (CSharp):
    1.  
    2. bezierMove.SetPath(myNewPath);
    3. for (int wpIndex = 0; wpIndex < bezierMove.events.Count; wpIndex++)
    4. {
    5.      UnityEvent pathEvent = bezierMove.events[wpIndex];
    6.      pathEvent.RemoveAllListeners();
    7.      pathEvent.AddListener(delegate {myController.ControllerMethod();});
    8. }
    9.  
    Any idea what I am doing wrong? Do I have to change or create the "events" list of bezierMove myself?

    Thank you!
    Felix
     
  29. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    Hey Felix,
    your code looks good i.e. same as in the demo script. Could you verify that the event is actually being added by placing a Debug.Log inside the loop? Unity events added at runtime do not show up in the inspector, so there is no way to see them there. You could also try initializing the bezierMove.events list and adding new UnityEvents yourself before that loop (hopefully you didn't really name your movement script reference "bezierMove").
     
  30. txl_muc

    txl_muc

    Joined:
    May 1, 2014
    Posts:
    6
    Got it. My fault. Thanks for your help.
    And yes I will follow your advice to change the name of the script reference :)
     
  31. TheEye2108

    TheEye2108

    Joined:
    Dec 25, 2015
    Posts:
    22
    I em making a game like zuma and have setup a spawner to spawn the shapes and add a path to them using:
    GameObject go = Instantiate (shapes [random]) as GameObject;
    go.GetComponent<splineMove> ().SetPath (WaypointManager.Paths ["ShapesPath"]);
    but i need to move those shapes when user clickes on 1 of those shapes but i think its not working because i need to remove the path from the game object i think ???
     
  32. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    From which gameobject? Paths are parented to the WaypointManager, and if you aren't using local tweens, then this is totally fine.

    You can pause & resume the movement of each object individually by calling the respective methods on the movement script. When calling from your own script, do not forget to add the SWS namespace. Otherwise your script won't find any scripts of SWS.
     
  33. TheEye2108

    TheEye2108

    Joined:
    Dec 25, 2015
    Posts:
    22
    there is no built in way to free the gameobject from the path like when ontouch position is inside the game object (sprite) it can be moved around. Ok then i can destroy that object and create a clone of it.
     
  34. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    If you pause or stop the movement script, you can move the walker object anywhere you like, as no further position updates from SWS are coming through.
     
  35. TheEye2108

    TheEye2108

    Joined:
    Dec 25, 2015
    Posts:
    22
    for me it just disappears so it must be something om my end
     
  36. TheEye2108

    TheEye2108

    Joined:
    Dec 25, 2015
    Posts:
    22
    void Update ()
    {
    if (Input.GetMouseButtonDown (0)) {
    Debug.Log ("Mouse Clicked");
    Vector3 mouseWorldPos3D = Camera.main.ScreenToWorldPoint (Input.mousePosition);
    Vector2 mousePos2D = new Vector2 (mouseWorldPos3D.x, mouseWorldPos3D.y);
    Vector2 dir = Vector2.zero;
    hit = Physics2D.Raycast (mousePos2D, dir);
    if (hit.transform != null) {
    hit.transform.GetComponent<splineMove> ().Pause (Mathf.Infinity);
    hit.transform.Translate (Input.mousePosition);
    }
    }
    }
     
  37. TheEye2108

    TheEye2108

    Joined:
    Dec 25, 2015
    Posts:
    22
    yea its my code
    hit.transform.Translate (Input.mousePosition);
    this does not work :D
     
  38. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @TheEye2108 also instead of calling Pause(Mathf.Infinity) you can just call Pause(). It's an overload, which does not create an additional (and in your case unnecessary) coroutine.
     
  39. TheEye2108

    TheEye2108

    Joined:
    Dec 25, 2015
    Posts:
    22
    Than's for your help :D
     
  40. K1kk0z90_Unity

    K1kk0z90_Unity

    Joined:
    Jun 2, 2013
    Posts:
    90
    Hi,
    Very good package, keep up the good work! :)
    I needed an event to be raised when the current waypoint in the path changes, so I made a simple WaypointChanged event for each type of path. I haven't tested it deeply yet, but it seems to work well. How can I send you the modified scripts so that, if you like the changes, maybe you could put them in the next version of the package?
     
  41. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    Hi @K1kk0z90_Unity,

    thank you for your feedback! Each movement script has an events section in the inspector where you can specify events per waypoint. In fact, movement scripts implement a WaypointChange method already! There is no single event slot in the inspector to call for all waypoints, but this can be done easily at runtime by adding a method to all waypoint events (2 lines of code). I'll rethink adding more special events to the inspector, thanks!
     
  42. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Hi,I want to generate obstkles on path.How can I get the path line in between two waypoints to know where to spawn obstkle exactly? so it falls under playable area?

    http://imgur.com/0jLT0zZ

    I want to place obstacles exactly where that yellow line going through...
     
  43. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Ok I solve the problem by ,

    Code (CSharp):
    1.         midPoint.transform.position = (path.waypoints[0].position + path.waypoints[1].position) / 2;
    2.  
     
  44. cranecam

    cranecam

    Joined:
    Nov 25, 2013
    Posts:
    25
    hi,
    I have splinemove and MoveAnimator on a character, but if I set the speed to a higher value in code, the character just "spins" on the floor before reaching the endpoint, and reversing the path (ping pong, full 3d, catmull rom). After reversing, it looks normal...
     
  45. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    Hi @cranecam,

    setting the speed value directly will only take affect on the next run, whenever a new tween for the moving object gets generated. Please use the ChangeSpeed method to also change the current tween timescale immediately. If that doesn't solve it, could you please provide steps on how to reproduce the issue you are experiencing.
     
  46. SVC-Games

    SVC-Games

    Joined:
    May 21, 2013
    Posts:
    137
    I just purchased DoTween Pro and I was wondering... If I want to use that instead of the included version in SWS I just remove the DoTween folder under SWS/Plugins or move the DoTween Pro folder there,replacing the contents?
     
  47. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @SVC Games
    Please completely remove our DOTween folder before importing DOTween Pro. After that, make sure to set your default DOTween settings again (linear easing etc.).
     
    SVC-Games likes this.
  48. IndusGeek

    IndusGeek

    Joined:
    May 21, 2014
    Posts:
    34
    can SWS be used for moving player along dynamic path ..like path being created at runtime as the player moves along the line infinitely. If yes can you please explain how.
     
  49. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,256
    @halflife SWS uses tweens for movement which are not designed for dynamic changes at runtime. In the case of an endless runner, you can certainly build your track out of multiple paths and create new paths dynamically after you have finished moving on the old one. I've posted instructions about how to do that on our website forum not too long ago.
     
  50. IndusGeek

    IndusGeek

    Joined:
    May 21, 2014
    Posts:
    34
    @Baroni
    Could you please direct me to the link. :)