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,264
    Hey wheelbarrow,

    it's good to know that you've solved it, thanks for the clarification :)
     
  2. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Our new website and dedicated support forum is online. If you would like to receive email notifications on product updates, please register in our forum and subscribe to the "Release Notes" topic.

    -- http://www.rebound-games.com/
     
  3. krillmcrawl0

    krillmcrawl0

    Joined:
    Jan 13, 2014
    Posts:
    35
    Hi!

    1. Import waypoints(spline positions), is it possible? I have a 1.5 km path in 3ds max. I can write an maxscript to export the spline positions but I need to know if it's possivle to import.
    2. I want to drive a train on the path, with speed controls (keyboard/mouse). Is't that something that is possible?
     
  4. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi krill,

    thanks for asking. In SWS, paths consist of gameobjects (be it waypoints or spline control points). So if your 3ds max script exports positions and your Unity script creates gameobjects from it, you would be able to assign these gameobjects to a path component. Second question: Movement scripts have a method named "ChangeSpeed" that lets you control the movement speed with a variable, e.g. with your keyboard input. It's all accessible via code.
     
  5. krillmcrawl0

    krillmcrawl0

    Joined:
    Jan 13, 2014
    Posts:
    35
    Great, just bought it!

    Ok I have a few hundred spheres now and want to use them as waypoints. Whats the quickest solution?

    Also, the speed variable seems to be read only when a lap is restarting. I need to control the speed along the path in order to simulate a train(up and down arrows to increase/decrease speed). Maybe I'm missing something?
     
    Last edited: Feb 28, 2014
  6. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Thank you for your purchase! Depending on the path component you would like to use, create an array with all of your spheres in the correct order and assign them to the "waypoints" array of a PathManager component (you could create a new one via code too). The PathManager component is meant to be for straight and curved paths.

    If you want to use bezier paths, you would have to create a BezierPoint class for each waypoint and additionally assign two control points (left + right) to this class, before adding it to the "points" list of a BezierPathManager component.

    Edit: Answering your additional question
    Right, you can't modify the speed variable at runtime. As I mentioned earlier, you should use the ChangeSpeed() method of a movement component what basically does the same by manipulating the tweens timescale.
     
    Last edited: Feb 28, 2014
  7. krillmcrawl0

    krillmcrawl0

    Joined:
    Jan 13, 2014
    Posts:
    35
    How do I do that by code, adding all children of a gameobject as waypoints, do you have a script example? Or maybe a button on the pathmanager that says, convert children to waypoints.

    Thanks!
     
  8. krillmcrawl0

    krillmcrawl0

    Joined:
    Jan 13, 2014
    Posts:
    35
    Adding a train on a path was simple enough. However when providing negative ChangeSpeed to the hoMove it starts moving backward correctly but at the first waypoint it arrives to it stops. Any ideas?
     
  9. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Here's some pseudo code (not tested) for adding children to the path manager waypoints array. It does not take a special order into account, so you may want to rename and sort children based on their name, for example, before adding assigning them to the waypoint array. The following script is an editor widget, you'll find it under Window > Simple Waypoint System > Custom Editor.

    Code (csharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System.Collections;
    4.  
    5. public class CustomPathEditor : EditorWindow
    6. {
    7.      public PathManager manager;
    8.  
    9.      [MenuItem("Window/Simple Waypoint System/Custom Editor")]
    10.      static void Init()
    11.      {
    12.         EditorWindow.GetWindow(typeof(CustomPathEditor), false, "Custom Editor");
    13.      }
    14.  
    15.      void OnGUI()
    16.      {
    17.           manager = EditorGUILayout.ObjectField(manager, typeof(PathManager)) as PathManager;          
    18.  
    19.           if (GUILayout.Button("Add Children"))
    20.           {
    21.                int size = manager.transform.GetChildCount();
    22.                Transform[] array = manager.gameObject.GetComponentsInChildren<Transform>();
    23.                
    24.                manager.waypoints = array;
    25.           }
    26.      }
    27. }
    Going further back than the latest waypoint won't work with the current movement scripts, as they loop over waypoints. That's why you would be stuck with the latest one. I'm not in the office at the moment but will provide you with a customized hoMove movement script early next week, if you wish to.
     
  10. krillmcrawl0

    krillmcrawl0

    Joined:
    Jan 13, 2014
    Posts:
    35

    I'm really impressed by your quick responses, thanks. Code for adding childrens as waypoints works great, I removed the first child since that is always the parent it's the parent!

    Code (csharp):
    1.         System.Collections.Generic.List<Transform> list = new System.Collections.Generic.List<Transform>(array);
    2.             list.RemoveAt(0);
    3.             array = list.ToArray();
    Yes that would be greatly appreciated, looking forward to customized hoMove movement script. I think that might be handy for others as well.
     
  11. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    I won't post the full script here though (most likely it excludes some functions). Instead I will send you a pm with the download link once I have finished coding it. Thanks!
     
  12. krillmcrawl0

    krillmcrawl0

    Joined:
    Jan 13, 2014
    Posts:
    35
    I have a path with about 1000 waypoints covering about 1 km in length(so about a meter apart for accuracy). When I look at the movement of a train/box it is really jumpy/laggy. Fps is good, close to 60. I have compared with a regular animation on the same path and that works without jumps. I don't see any big difference between, itween or Hotween.

    Not sure why it lags, is it the amount of waypoints or something else? Some settings I can manipulate to make it smoother?
     
  13. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    That's probably because of the additional checks for each waypoint (delays/messages). 1 waypoint per meter is very extensive, especially if your train moves at high speed. The minimal version I'm going to send you won't have these checks and won't loop over all waypoints, but create a single path with one animation.
     
  14. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    I just sent you a pm with the download link for the minimal version of hoMove (without waypoint loops, delays and messages), which should better suit your needs. This script will be included in the next update, along with some other example movement scripts.
     
  15. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Version 3.2 is live.

    Features
    • hoMove: configurable starting point (does not work with looptype random)
    • hoMoveMinimal: new performance efficient version of hoMove, without messages, delays and looptype random. Does not use partial paths
    • New example scenes: camera flythrough rapid input (see webplayer)
    • New FX script: PathIndicator component spawns particles along a path
    • Experimental: new components MoveRenderer PathRenderer allow rendering of tweens (hoMove) or paths (PathManager) at runtime by using Line Renderers
    Fixes Changes
    • Project restructured for easier browsing (Assets, Examples, Plugins, Scripts)
    • “Place to Ground” setting on path managers works with 2D and 3D colliders
    • hoMove: fixed triggering of messages at the last waypoint
    Tween and path renderers are experimental and can be found in the Examples > Scripts folder for now. I'd like to extend them to more mobile friendly procedural mesh versions (not LineRenderers) in a future version. Here's the new web player for this release:
     
  16. petak_core

    petak_core

    Joined:
    Nov 19, 2012
    Posts:
    57
    Hi Baroni,

    first thank you for your great Asset SWS is simple awesome.

    I have some questions about that:
    1)how is possible to do simple "reverse" go... I would like do to reverese go for my car.
    (for example Looptype as PingPong (but I won't wait to end of path. I would like to go backward mmediately))
    (or oposit for Car.GetComponent<hoMove>().ChangeSpeed(10) to Car.GetComponent<hoMove>().ChangeSpeed(-10)

    is there any easy way to do it.

    thank you for any help
     
  17. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi petak,

    thanks, nice to hear that!

    If you're not using any messages or delays on the path, you could try the new minimal version of hoMove (hoMoveMinimal) that was added in 3.2. It does not tween from waypoint to waypoint, but on the path as a whole, so you are able to use Car.GetComponent<hoMoveMinimal>().ChangeSpeed(-10);.
     
  18. Andy2222

    Andy2222

    Joined:
    Nov 4, 2009
    Posts:
    81


    • Just re-imported the project and while i could easily deselect the plugins i have already installed (itween/hotween), i had to manually search + guess what assests belong to just the examples i don't want to import and which are related to the editor debug rendering of the system.

      Would be nice to have something like:
      SWS
      -- Scripts
      -- Assets

      [optional] folders
      -- Plugins
      -- Examples
      ----- Scripts
      ----- Assets

      This way u can easily deselect plugins/examples depending on what u want to import.

      Thx
      Andy
     
  19. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Actually it already is structured like that, with the main "Scripts" and "Plugins" folder being necessary for SWS to work properly. "Assets" and "Examples" could be removed for a minimal installation. What do you mean by the editor debug rendering?
     
  20. Andy2222

    Andy2222

    Joined:
    Nov 4, 2009
    Posts:
    81
    Ah my fault i was assuming i need "PathIndicator", "PathRenderer", "WaypointGizmo" for the package. I just deleted the whole asset folder and works fine.

    Thats why i think having assets under the examples folders is a better approach, it makes "guessing" easier. In this case i would have assumed that those assets are example only assets. Thats because many other packages have a "asset" folder with icons/textures/materials, they actually need for normal operation.

    thx
    Andy
     
  21. WizardGameDev

    WizardGameDev

    Joined:
    Jul 25, 2012
    Posts:
    62
    How does this interface with Mecanim animations and transitions? I've been looking for simple way points system that my mecanim characters can go from idle, walk, pause at a way point, then keep walking... like for a patrol. Is that possible with SWS?
     
  22. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Thanks for asking! Much work has gone into the next version of SWS (v4), with Mecanim controllers and animators as one of its features. Right now I am working on the documentation and am planning on releasing it this coming week.
     
  23. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    HI Baroni.

    I get this error:
    IndexOutOfRangeException: Array index is out of range. hoMove+<NextWaypoint>c__Iterator29.MoveNext () (at Assets/SWS/Scripts/Movement/hoMove.cs:331)

    When trying to use multiple objects to move over one path - at some point (waypoint) some object just stop and i get this in console.
    HoMove minimal works fine.

    Any idea?
     
  24. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi Chris,

    in this case the line in question is:
    Code (csharp):
    1. if (StopAtPoint[currentPoint] > 0)
    It seems that the script is trying to access a slot in the StopAtPoint array that does not exist. That array is initialized in the StartMove() method and shouldn't change when objects move on their path... how could I reproduce this? Have you just assigned multiple objects to one path in the editor or do you change them at runtime?
     
  25. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    Object are being created by Core Game from Dark Tonic(as far as I understant first at run time they are pooled to pool boss and than moved to spawn point) , just after instatiation I use playmaker action (provided by you) SWS Set Path. Hope you understand me.
     
  26. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Yes, I understand you well. I will try to reproduce it with the PlayMaker action tonight. If I can't get it to spit out that error then I'll contact you with a private message here.
     
  27. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
  28. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hey Chris,

    you should uncheck "On Start" on your walker prefab to avoid this error. Otherwise, if you let "On Start" enabled, spawn the object and call SetPath afterwards, the movement routine would be running twice and most likely causes this error. Hope that helps! (trying to implement a sanity check in the next version)
     
  29. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    Thanks for fast support! And sorry to take your time :)
     
  30. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    Hi Again,

    is there a way to set delay on waypoint when the path is being set on run time(I canot set the path on prefab)? - best would be playmaker solution, I am a playmaker user.

    Also I have notice that hoMove minimal works much smoother than, hoMove (20-30 models on path), when I use hoMove normal I get units to stock sometimes for part of a sec ... Why is that?

    Kind regards
    KZ
     
    Last edited: Mar 17, 2014
  31. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hi there,

    the PlayMaker action "SetDelayAtNode" would do exactly that, you only have to specify the walker object, waypoint index and delay value.

    hoMove has additional checks for messages and delays, which are executed in separate routines. The execution of these routines is barely visible on slow objects (1 frame), but can be visible on faster ones. hoMove minimal is a performance efficient version without these checks, therefore it does not allow for messages or delays in return.
     
  32. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    Hi again,

    I checked twice before posting and couldnt find it, now I see it ... :)

    By fast speed you mean speed : 5+?
    Also I notice that if more than one model in hoMove on the same path, units tend to lose formation (some get delay on waypoints, some dont) - i dont know is it working properly or I did set something wrong.

    KZ

    ps. I like your tool and support, gave you 5 stars :)
     
    Last edited: Mar 18, 2014
  33. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Thank you very much for your support! ;)

    "Fast speed" depends on the size of your path and game time, but something between 10-15+ would be appropriate I think. Yesterday I tested the "On Start" issue with 40 objects on the same path and didn't notice missing delays... You can check whether the walkers without delays actually have delays set by expanding their "Show Delay Settings" field at runtime, maybe something else is going on with PlayMaker?
     
  34. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    For test purpose I have 5 objects and i get delays (they get stuck for micro seconds from time to time), i turned off all the scripts on object in question and all fsm.



    Only on hoMove normal thought.

    Path legnht: 34
    Speed: 5

    Edit: same with just only one object.

    I think there must be something wrong with my scene, your exaple scenes work just fine. Dont know what it is thoguht.

    One thing that crossed my min,to set waypoint I used plane (but 3d mode on) when I set waypoints they always get +5 on Y axis - dont know could this be the cause.
     
    Last edited: Mar 18, 2014
  35. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Hmm.. a customer reported strange results with hoMove not too long ago and I could pinpoint it to damaged Unity meta files when upgrading. I'm not sure if that helps in your case, but in that case removing hoMove and attaching a new one to the object fixed it. Otherwise I'm a bit clueless right now.

    In 3d mode the Waypoint Manager raycasts against colliders (your plane). If your plane is located at +5 on the y-axis, your waypoints would be placed there too.
     
  36. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    I just checked scene Exaple curved, plaved 4 object, speed 10 pathrol path 4 and same behaviour (less frequent than in my scene, but still).
     
  37. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    Just started new project, importer SWS, opened Exaplne curved, placed 6 boxes, spacing 2 units on X axis, set path to path pathrol 4, on start enabled, move to path enabled, orient to path enabled, speed 10, at same result, micro delalays, boxes lose patern after some time.
     
  38. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Thanks for investigating this further, I can now see this happening on my end too. I'm in the final stages of releasing a new version and will double check if it is fixed there. Should be out this week!
     
  39. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    No problem :) Thanks too.
     
  40. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Have you had the chance to look at the PlayMaker sample scene and its AddMessageAtNode action? The walker object would be your object with the movement script attached to it, while FSM receiver is the object that holds the FSM with the event - these could be two different objects.

    In the sample scene a message is added to the walker object (Capsule5) at start, to waypoint 1. The actual message is to call the FSM event (EventCall) on the FSM receiver object (AddMessageAtNode).
     
  41. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    Damn, deleted my previous post by mistake. Why pick receiver object, if you cant pick diffrent than the owner of FSM at the same FSM that its action placed. Why not delete fsm receiver slot, and change fsm event to send event(this is more playmaker action structure correct in my opinion).

    Right now the construction of your action makes you think thath you cn send events betwin diffrent objects and fsm.

    Or maybe you can and I dont know how to do it?
     
    Last edited: Mar 19, 2014
  42. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    You can do this when using custom events. The FSM owner does not have to be the receiver. In our example, the gameobject "AddMessageAtNode" calls the event "EventCall" on itself, but this event could also be located on another FSM.
     
  43. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    It doesnt work for me on other FSM or other Object - that was the meaning of my first post- and it shouldnt work in my opinion, because you dont have FSM name text fild to setup.
     
  44. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    $swsproblem1.png
    $swsproblem2.png

    Both FSM on the same object.
     
    Last edited: Mar 19, 2014
  45. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Umm.. yeah you are right, it doesn't work with two FSMs on the same gameobject. I made a quick test using different gameobjects:

    MessageSenderFSM
    MessageReceiverFSM

    The first screenshot shows the add message action, with the receiver set to a different object. The second screenshot shows the receiver gameobject after its event has been fired (through the other FSM). Ultimately you would have to use two different gameobjects, e.g. one "setup" gameobject and one "receiver" gameobject.
     
  46. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    Any fix soon?


    It also crashed my unity when on play mode, when trying to use on one game object with many FSMs on it.

    My suggestion is to analise the switch actions from original playmaker and send event.

    ps. I am kinda sure that you are missing FSM Name field.

    I am verry weak programer (started learning 3 months ago), so writing custom action for me is kinda a problem... I get the logic usually right, but low expirience makes looking for wrong size character to long :) That is why I use playmaker for now.
     
    Last edited: Mar 19, 2014
  47. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    I wouldn't know what to fix, sending events between objects is working with my FSMs as you can see in the images. When Unity is crashing with many FSMs then that wouldn't be related to SWS but rather to PlayMaker itself I guess. Why don't you create two separate gameobjects with one FSM each?
     
  48. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    I can do that, but in my opinion this is a bug :) (not being able to send to an object with more than one FSM and using global event even if you dont need it(why use global event for single fsm single object action??).Please take a look at switch send event action in oryginal playmaker, I knew your action wont work before i tested it, cause it was missing FSM name field.\

    Unity crashed when was on your action serveral times in a row- message one.

    Never any other action crashed this way for me.
     
    Last edited: Mar 19, 2014
  49. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    Will do. It won't happen in the coming release though, because I would like to get it out this week.

    It does not have to be a global event - it's not a global event in the image I uploaded either (but two different gameobjects).

    You are the first PlayMaker user reporting this, please bear with me while I try to figure out what could or could not be happening.
     
  50. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    No problem.

    When you click on the list of events you can fire, all that show up are the globals.