Search Unity

Simple Waypoint System (SWS) - Move objects along paths

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

  1. cel

    cel

    Joined:
    Feb 15, 2011
    Posts:
    44
    lets say I have 2 paths with 10 waypoints each running parallel to each other and a mover in path 1. Can I change the mover to follow path 2 from waypoint 5 onwards. What I mean is does sws allow the mover to change paths at any stage to another waypoint in another path?

     
  2. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    Hey cel,

    I don't know if you bought SWS already, so first, SWS allows that if you change 2 lines of code. As for how it works:
    The 'currentPoint' variable of iMove indicates the walker's current position. This variable gets resetted each time you change a path - this means that your walker will start from the beginning once you switch from path1 to path2 or 2 to 1. Edit that 'functionality' by adding another parameter to the SetPath() method in iMove.cs:
    Code (csharp):
    1. public void SetPath(PathManager newPath, int desiredWaypoint)
    and to apply the new desired waypoint, within this function:
    Code (csharp):
    1. currentPoint = desiredWaypoint;
    Once you want to change the path, you call SetPath('desired Path', 'desired waypoint index of that path') and your walker object will then move to it. So in your case, between waypoint 5/6 you call SetPath(Path1, 8) and the walker will directly move to waypoint 8 of Path1. Please note that it will walk in a straight line, like in this image.


    Good luck!
     
  3. josemauriciob

    josemauriciob

    Joined:
    Mar 5, 2009
    Posts:
    657
    hi ..
    this is the best waypoint i saw.
    but just have a question .

    what do I have to do ( or add ) to the red capsules, to collide.
    i need they collide if two of them were in the same way.

    thanks
     
  4. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    Good evening imaumac,

    thank you.

    If two gameobjects should collide, they need a collider and a rigidbody attached to them. The capsules should have a collider already, so they only need a rigidbody ( Menu - Component > Physics > Rigidbody ). Uncheck 'Use Gravity' and 'Is Kinematic'. Basic idea here is: When two capsules collide, they should stop moving and collapse. We have to code this behaviour, insert this method into iMove.cs:

    Code (csharp):
    1. //called on every collision
    2. void OnCollisionEnter(Collision col)
    3. {
    4.    //check if we collided with another capsule
    5.    if (col.gameObject.name.Contains("Capsule"))
    6.    {
    7.       //stop iTween's movement
    8.       Stop();
    9.       //enable gravity of this capsule/object so it collapses on impact
    10.       gameObject.GetComponent<Rigidbody>().useGravity = true;
    11.    }
    12. }
    SWS really is very expandable and just a starting point for lots of actions, there's no limitation to its functions. Hope that helps,

    best regards
     
  5. cel

    cel

    Joined:
    Feb 15, 2011
    Posts:
    44
    is there a way to retrieve which waypoint in a path the walker is at the moment?
     
  6. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    @cel
    Please take a look at my first reply, where I described the use of currentPoint. You could mark currentPoint as public variable and get its value from an other script. If it is 0, the walker moves or stays at the starting point (waypoint 1). If the value equals 1, your object moves to or waits at waypoint 2 and so on.
     
    Last edited: May 24, 2012
  7. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    Hey all,

    just submitted v2 with the awaited support for curved paths!
    I also updated the first post and included a version history.
    It may take a while until it gets accepted, but here's a sneak preview:



    At this point, thanks to Daniele for his outstanding work on HOTween!
     
  8. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,234
    Thanks to you Baroni! Simple Waypont System looks really awesome in its simplicity. Will jump on board soon :)
     
  9. potter3366

    potter3366

    Joined:
    Oct 15, 2009
    Posts:
    41
    In the download list in the asset store it still shows the Simple Waypont System as "v1.2"...
     
  10. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    Yes, v2 is still pending approval. Please be patient and check back soon, I will post the status here.
     
  11. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    Great news: Version 2 has been accepted and is available on the Asset Store out now!

    MADNESS OFFER: 33% OFF until June 23rd.
    For almost a month the price stays at $10, before it rises to $15.

    Get it while it's hot!

     
  12. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    804
    Sweet! :)

    The documentation included in the package still refers to v1.2, though... or is there something wrong with my import?
     
  13. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    I replaced the documentation with v2.0 and updated all chapters, could you please try to import SWS into an empty project?

    I will also double check my package on the Asset Store, though.
     
  14. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    804
    Indeed, it's v2.0 in a fresh project.
     
  15. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    Glad it worked, thanks!
     
  16. TTkJonas

    TTkJonas

    Joined:
    Mar 21, 2012
    Posts:
    28
    Hi
    I have buyed the pack, imported it into my game Project. When I click play in the sample scene, all works. But when i click on a path, i miss some Buttons in the Inspector. What do I wrong?
    I use Javascript for my game and i used iTween before i have buyed this
    And sorry for my bad english ;)

    *Edit*
    Problem Solved. I have easy reimported the whole files. No it works :)

     
    Last edited: Jun 4, 2012
  17. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    Hi TTkJonas,

    thanks for your purchase and sorry, that looks very odd.

    Have you tried importing SWS into an empty project before?
    You could try to move all editor scripts of SWS located in your folder 'Editor' into a new folder called 'Standard Assets' > 'Editor' (I don't see the Standard Assets folder in your project, so you have to create this one).

    We can discuss details per pm in german if you like.

    Edit: I just saw that you're missing a file, 'PathEditor.cs'. That file also need to be located in the Editor or Standard Assets > Editor folder, please import it again.

    Regards
     
    Last edited: Jun 4, 2012
  18. GamesByJerry

    GamesByJerry

    Joined:
    Oct 27, 2008
    Posts:
    71
    Recently purchased this, too great of an offer, there's a couple features I would love to see added for optimization purposes.

    Ability to toggle a bool in iMove/hoMove to pretend the GameObject's current position is the first waypoint of the chosen path.

    Benefits:
    - Use a single path multiple times, saving ram taken up by excess gameobjects
    - Reduce the current method of writing lines of code with a single checkbox
    - Due to the caching requirements further speed improvements by accessing vector3 variables over multiple gameobject transforms.

    A further step in optimization would be to allow the "baking" of waypoints, either in the editor or at runtime, into vector variables to reduce ram and give a speed boost to us mobile developers. In order to replicate the visual pathing in the editor during runtime you could use line rending, enabling the feature could require Vectrosity to save coding a decent line renderer?

    It's a huge amount of effort, but just wanted to spill out my ideas while they were fresh! In any case I'll probably have to add some of the above to ensure a smoother experience on mobiles, if I do I'll be sure to share with the community :)

    Otherwise so far loving it, valued purchase!
     
  19. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    Hey Tagged,

    thanks for the feedback!

    I may have misunderstood something regarding this idea, have you tried to uncheck MoveToPath - doesn't this give you the desired result which directly positions the gameobject at the first waypoint of the path?

    Caching of waypoint positions as vector3 values requires little effort, I implemented that a while ago, but threw it out for allowing path updates at runtime. For this reason iMove/hoMove access a reference to waypoints. If you don't change the path's position at runtime, you could store a dictionary with vector3 values of all waypoints per path in the WaypointManager component, instead of storing PathManagers, and initialize them once. Then iMove/hoMove could access these positions as before.

    I don't use Vectrosity right now, however I will see if rendering visual replications of a path during the game is an option somewhere. Let me know if you make progress on any of these ideas or if we talk past each other. Thanks!
     
  20. taku

    taku

    Joined:
    Jun 5, 2012
    Posts:
    24
    Is it going to be a difference between the full SWS and the one used in your 3D Tower Defense Starter Kit? Thanks
     
  21. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    Hi taku,

    yes, absolutely. SWS is a standalone path creation and movement system, while in our TD Starter Kit we only used the very basics, modified and even discarded some features of it. Maybe we switch our Kit to curved movement at some time, but it will never contain all the features.
     
  22. GamesByJerry

    GamesByJerry

    Joined:
    Oct 27, 2008
    Posts:
    71
    Hey Baroni!

    Thanks for the fast response!!

    The dreaded difficulty of explaining things in text. Ok bare with me on the programmer art...

    $Pathreuse.png

    There's only the one path in the above mock up. The two red squares each act as if they are currently at the start waypoint and change their position relative to the distance between waypoint 1 and 2 rather than an absolute position.

    Hope that's clearer :)
     
  23. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    It is, thanks. Ok, that you meant with several waypoints but one path... you're right, this scenario would require 2 single paths at different positions. Relative movement... I will bear that in mind for the next time! I like your sketch, very understandable as a programmer myself :)
     
  24. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,234
    Hey,

    I just wanted to jump in and say that I used Simple Waypoint System for a quick game prototype (Uberbleibsel), and loved it. Setting up paths is a breeze, and a thing that struck me is that usually, each time I duplicate a level to build new stuff, the idea of deleting anything terrifies me (since most of the time re-creating stuff while remembering the correct variables is a pain), while instead SWS is so speedy, that I felt safe enough to just delete all paths and create new ones in a matter of moments.

    Great job Baroni :)
     
  25. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,013
    I already had itween installed form another asset in a different location, is there a standard location for itween that all developers use so this conflict can be avoided?
     
  26. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    Hey Lars,

    I don't know a standard location, but it is used to be placed either in the Plugins or Standard Assets folder. In my case I also wanted to credit the authors, so I left them in their original folders. Seems like there's no way around other than unchecking both plugins before importing, or deleting them afterwards.

    @Izitmee
    It's an honor that you use SWS! Thanks so much for making internal functions possible :)

    Regards
     
    Last edited: Jun 6, 2012
  27. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,013
    Scripts named 'iTween.cs' exist in multiple locations (Assets/iTween/iTween.cs). Please rename one of the scripts to a unique name.

    This is the location I already had, I will use this one for now and uncheck the SWS version on import, could you tell me with version of itween you include, so I can see if I need to update to that one?

    Thanks
     
  28. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    I included version 2.0.45 and made no changes to it.
     
  29. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    804
    As far as I know C# scripts don't care about the location as much as UnityScript does.
     
  30. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,013
    I have everything working now, the Hottween version looks really nice! thanks for putting that in.

    The only thing I can't do is select the waypoints form the editor window, I can only select then from the hierarchy.

    Is there a way to do this directly?

    Thanks
     
  31. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    You may want to take a look at your similiar question a while ago:

    I didn't put that solution in, because waypoints will easily get into your way when you try to move other things around, I don't want that to happen all the time. However, as mentioned, you could try switching Gizmo.Draw to Gizmo.DrawIcon, this method only needs an icon texture.
     
  32. mikevanman

    mikevanman

    Joined:
    Sep 30, 2009
    Posts:
    108
    just a quick question

    is their an option (or bit of code) to not orientate when going up an incline, basically when I set the waypoints going up stairs the character is leaning back at the angle of the slope.

    if that makes sense , just could find an option to stop this.
     
  33. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    Hello mikevanman,

    which movement script do you use? In hoMove, there's an option in the inspector to lock an axis, that could be useful in your case.
     
  34. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,013
    I see your point however I like to move them all the time, and can easily disable other objects when they get in the way.

    Any change to put it in the next version? I'm no programmer and have no idea how to implement the suggested Gizmo.DrawIcon.
     
  35. mikevanman

    mikevanman

    Joined:
    Sep 30, 2009
    Posts:
    108
    cheers Baroni I had not looked at the homove script, although tried the lock to axis option but this seems to make no difference , the character still leans back when going up a slope.

    anyone found a solution to this?
     
  36. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    Whew, this one took me an hour. Just found out that handling Gizmos is a pain and additionally, Gizmo.DrawIcon doesn't work at all. I sent you 2 modified scripts with a short instruction via pm.

    Selecting waypoints in the viewport is also going to be in the next update.
     
  37. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    Hey mikevanman,

    I implemented a lock-axis variable for iMove, it "should" do what you want. Example image
    "Should", because it's kind of hacking iTween to limit its functionalities, could occur a little stutter. PM sent.

    Regards,
    B.
     
  38. matte.szklarz

    matte.szklarz

    Joined:
    May 29, 2012
    Posts:
    10
    I also am really enjoying SWS, and I slowly starting to add some extra needed functionalities... I needed Super Mario "World 1.2" style platforms (infinite repeating rising/falling platforms) and I sort of solved Tagged's problem in the process.

    I wrote code into the iMove script that detected the nearest waypoint for you/where to being, but it didn't like curved paths, and realized that it was much simpler to just manually set which waypoint is "first" as far as that game object is concerned.

    So, for the Mario Platform example, I have three path-following-objects set along the two-waypoint path with appropriate distances between one another. They are as close to the correction path position s possible. Each of them have firstWaypointGoal set to 1 (since waypointStart is "0", didn't want to mess with that). They need to be set to speed, not time for this to work, you'll see why if you try time. ;)

    Also, be aware that I changed some variable names to make more sense to me, moveToPath's functionality seemed backward to me, so I renamed it "startOnPath" and I added LoopType.closedLoop which was a secondary effect that moveToPath used to have (tween back to start from end, rather than jump there); startOnPath should only "fire" once at play.
     
    Last edited: Jun 7, 2012
  39. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    If someone is interested in Matte's custom iMove script, please pm me your Asset Store invoice number so I can verify your purchase.

    @matte
    Thanks for this addition, I will try it out very soon.
     
  40. dcdemars

    dcdemars

    Joined:
    May 18, 2012
    Posts:
    16
    I'd like to revisit a problem that was discussed here back in February as I didn't find the reply completely satisfactory. I'm referring to the following exchange:

    > Lars Steenhoff:
    >
    > could you please add a rotation offset variable in the editor by orient to path setting.
    > Thanks

    > Baroni:
    >
    > @Lars
    > PM with new rotation code sent. I don't want to add all user requested variables
    > to SWS because that would bloat the kit. The full source code is documented and
    > therefore pretty easy to understand.

    I just bought SWS and I immediately had a problem the first time I tried it because the animated character I was using did not have the correct orientation; that is, it is not facing in the direction that Unity regards as "forward". This asset was imported from the Asset store and I have no power to change the character's orientation.

    This is actually a common problem with models imported into Unity, and there is a "standard" way to handle it that usually is mentioned when this subject comes up. I say "standard" because it is actually in the Unity manual:

    http://unity3d.com/support/documentation/Manual/HOWTO-FixZAxisIsUp.html

    So, to apply this solution, I create an empty game object, make my character object a child of that, and rotate the child within the parent's space so that the character is facing in the correct direction in parent's space. In my case, I had to rotate it -90 degrees around the Y axis to achieve this.

    To use this with SWS, the hoMove script has to be a component of the parent so that its transform is the one that is manipulated. This almost works; the only catch is that hoMove cannot access the child's Animation component. Adding an Animation component to the parent doesn't help, hoMove needs to use the child's Animation component. Right now, it accesses the "animation" convenience property in the parent, which can't be changed at initialization because it is a read only property.

    The most straightforward way to solve this is to change the four places in hoMove where the animation property is used and make sure that the child's animation property is returned when the current object has no animation property. One way to do it is to change all references to animation to instead use GetAnimation() and then add the following function to the hoMove script:

    private Animation GetAnimation ()
    {
    Animation result = animation;
    if (result == null) {
    result = GetComponentInChildren<Animation> ();
    }
    return result;
    }

    Now everything works; unfortunately, this will get wiped out if I ever install an upgrade to SWS.

    I suggest that something like this be added to SWS; it would not change the user interface (no additional inspector variables needed) and everything that currently works with SWS would still work.

    Although I haven't seen any other complaints about this problem on the thread, I can't believe that this isn't a common problem.

    - Dennis D.
     
  41. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    Hi Dennis,

    sorry for the inconvenience about the handling of animations. I think the code I sent to Lars Steenhoff wasn't related to this issue, otherwise I would have fixed it this time. Also thanks for your very detailed post, very easy to read and follow along. I haven't ever thought of such a use case, because no one complained... however I like your approach, thanks for bringing this up. A similiar approach will be in the next version soon.

    Greetings
     
  42. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,013
    I also fixed the rotation issue I had by parenting under a new game object :) , and the rotating the child object 90 degrees.
    I put the animations on the new parent and it works for me, even with the hoMove.

    For me it is not a rare use case because many assets form the store have the "wrong" forward setting.
    I'm glad I'm not the only one anymore :)

    Good work on the plugin, It has become the main way of animating objects along a curve for my game.
     
  43. dcdemars

    dcdemars

    Joined:
    May 18, 2012
    Posts:
    16
    > I put the animations on the new parent and it works for me, even with the hoMove.

    This was the first thing that I tried and it didn't work for me. hoMove would go ahead and use the animation, but the clips didn't have the desired effect. Although the solution I arrived at does work, I think I'll try putting them on the parent again to see if I did something wrong the first time.

    I'd like to ask (because it may be relevant), are the animations you are using clips that you made yourself, or third party animations that were imported with your model?
     
  44. dcdemars

    dcdemars

    Joined:
    May 18, 2012
    Posts:
    16
    > sorry for the inconvenience about the handling of animations. I think the code I sent to Lars Steenhoff wasn't related to this issue,
    > otherwise I would have fixed it this time.

    I probably jumped to conclusions because I was looking through the thread to find out if anyone had already solved the problem.

    Anyway, thanks for taking a look at it. Great support for an inexpensive extension!

    - Dennis D.
     
    Last edited: Jun 7, 2012
  45. GamesRUs

    GamesRUs

    Joined:
    Apr 8, 2012
    Posts:
    17
    Hi all,

    I didn't like how the waypoints are just named 'Waypoint' plus I wanted to be able to make a closed loop, so I added the following block of code in the 'OnInspectorGUI' method of the 'PathEditor.cs' file to perform those two functions. Just thought I'd share these since someone else might find them useful. Note the '+ 0.00001f' in the 'close loop' which allows it to actually loop properly with the start and end points being slightly different.

    Thanks



    EditorGUILayout.Space();

    //Rename all waypoints in the order to be executed to make it easier to select the one you want to move
    if (GUILayout.Button("Rename Waypoints By Index"))
    {
    //register all scene objects so we can undo to this current state
    Undo.RegisterSceneUndo("WPRename");

    for (int index = 0; index < waypoints.Length; index++)
    {
    Transform wayPoint = waypoints[index];
    switch (index)
    {
    case 0:
    wayPoint.gameObject.name = "Waypoint Start";
    break;
    default:
    if (index == (waypoints.Length - 1))
    {
    wayPoint.gameObject.name = "Waypoint End";
    }
    else
    {
    wayPoint.gameObject.name = "Waypoint " + index.ToString ();
    }
    break;
    }
    }
    }

    EditorGUILayout.Space();

    //Move the end waypoint to the location of the start waypoint to allow for a closed loop.
    //The loop type selection should be loop or none to work right.
    if (GUILayout.Button("Close Loop"))
    {
    //register all scene objects so we can undo to this current state
    Undo.RegisterSceneUndo("WPCloseLoop");

    Transform wayPointStart = waypoints[0];
    Transform wayPointEnd = waypoints[waypoints.Length - 1];
    Vector3 startPoint = new Vector3(wayPointStart.position.x + 0.00001f, wayPointStart.position.y, wayPointStart.position.z);
    wayPointEnd.position = startPoint;
    }
     
  46. zaxvax

    zaxvax

    Joined:
    Jun 9, 2012
    Posts:
    220
    Great system. I was playing with it for 2 days and I found only one major problem.
    Speed and animation speed are not connected and it gives some unacceptable results. It doesn't matter when you have some loop idle animation like platform or spaceship, but with walking animation like human walking it's very bad. Human will move his legs with the same speed, no matter how you change iMove speed. AnimationState is helpful if your character has constant speed, but if speed varies or Easetype is other than llinear it won't work.
     
  47. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    Hi, I checked your code. First, all works well! But I found two disadvantages:

    Renaming waypoints breaks the ability for displaying different icons, because the Waypoint Manager can't recognize what's a starting/ending point and what is not. To fix this, that would require some one-liner modifications in Waypoint Manager.

    Closed loops are a desired side-effect of "moveToPath". Is your loop selection = loop with moveToPath checked, an additional iTween call gets created at the end of the path which moves a walker to the first waypoint. In this case it obviously gets created but does nothing, because the waypoints are placed nearly at one position. So you can't / or shouldn't (regarding performance) use moveToPath with this setting. It works well for loop type none, though. Another point is, if you have set a delay at both (first and last) waypoints, your walker waits two times at the same position.

    All in all good contribution, thanks!
     
  48. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    Hi Zaxvax,

    thanks for your feedback. I'll see if I can find some relations between speed and animation speed, need to figure out how iMove/hoMove's speed variable can regulate animation speed at all, so that it doesn't seem independent. Maybe tweening the speed variable on easetypes needs another iTween call, but I want to prevent this. I'm on it.

    Regards
     
  49. zaxvax

    zaxvax

    Joined:
    Jun 9, 2012
    Posts:
    220
    It's not so imnportant for my current project as I can just tweek animation speed before I start character movement, but It will be a very nice feature to use in future. Thank you in advance. :)
    If you will also add bezier curve support some day, then you can just rename SWS into Perfect Waypoint System. :D
     
  50. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,386
    Haha, alright thanks! Bezier curves are a complete different story, but maybe the day will come :)
     
unityunity