Simple Waypoint System (SWS) - RELEASED

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

  1. TTkJonas

    TTkJonas

    New Member

    Joined:
    Mar 21, 2012
    Messages:
    28
    I have the same problem. Thats bad for use in 2D Games ;-)
     
  2. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    I know that the lock-axis option produces trouble in certain situations, but it's difficult to debug without any further data. Most likely it behaves incorrect when using different heights for the waypoints, however that seems not the case here. I'll see what I can do, though.
     
  3. vicour

    vicour

    New Member

    Joined:
    Feb 29, 2012
    Messages:
    13
    I think I found the problem. (not a SWS problem)

    A parent of my vehicle object had a rigid body physics controller on it, I think the path was conflicting with the controller. Since removing it, the path has been perfect in both iMove and hoMove. I will post again if the problem appears again.
     
  4. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    Thanks for pointing that out!

    Glad you solved it. Maybe the rigidbody tried to let the object fall down while the hoMove script tried to move it along the path.

    Yes, please keep me posted.
     
  5. c-Row

    c-Row

    Member

    Joined:
    Nov 10, 2009
    Messages:
    742
    Hey Baroni

    Is there any way to find out the length of a path? Just want to make sure that four separate paths are all of equal length since movement will be based on speed rather than time.

    Cheers,
    Thomas
     
  6. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    Hi Thomas,

    the Path Manager component already displays a "straight path length". This is useful in case you use iTween for straight movement. If not, in HOTween there's the alternative to find out the duration of the tween via myTweener.duration (read-only property). You could debug this at the end of hoMove's Move() method, where the tween gets created.
     
  7. c-Row

    c-Row

    Member

    Joined:
    Nov 10, 2009
    Messages:
    742
    I intend to use curved paths, so I guess the latter option is the one I should look at then. :) Is either iTween or HOTween capable of changing movement speed while on a path? Can't test this myself at the moment, but I guess it's possible judging from the user controlled path movement example...?
     
  8. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    Unfortunately not. The user controlled capsule uses iTween's PutOnPath() method and therefore does not create a tween at all, for changing the speed of a tween you would have to destroy and recreate it every time... Recreation is a bit difficult with my HOTween implementation though, because HOTween inserts a controlpoint at the position it starts tweening by default, this could cause weird stutter or position jumps.

    Edit: You could also download the full source code of HOTween (and maybe donate a buck at the same time? :) ), its PlugVector3 path implementation has a way to retrieve a time - length table :)

    Edit2: Daniele, the knightly author of HOTween, just reminded me that changing the speed of a tween is indeed possible (totally forgot that, because I only thought about movement speed) using the tween.timeScale variable. You would just have to set the movement speed accordingly then, so it does not revert when it's finished.
     
    Last edited: Jul 13, 2012
  9. c-Row

    c-Row

    Member

    Joined:
    Nov 10, 2009
    Messages:
    742
    My idea was to have an object on a path that slows don to a halt when the user presses a button and accelerates back to its standard speed on release. Or maybe just stopping and restarting if a gradual speed change is out of the question.
     
  10. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,417
    Sorry if I intrude, but I have an idea about how that could be done :p

    You could store a variable (a float of value 1) that represents the timeScale of the path tween. Then:
    - you create and store an HOTween Tweener (let's refer to it as myTSTween) that animates the variable to 0, and keep it paused
    - when the user presses the button, you play myTSTween, and use its OnUpdate callback to update the path animation's timeScale, based on the changed timeScale variable
    - when the user releases the button, you revert myTSTween (myTSTween.Reverse()) and play it backwards, still using the same OnUpdate callback to revert the timeScale of the path animation
     
  11. c-Row

    c-Row

    Member

    Joined:
    Nov 10, 2009
    Messages:
    742
    Sounds like a plan. :) I'll see if I can come up with a prototype tomorrow.
     
  12. c-Row

    c-Row

    Member

    Joined:
    Nov 10, 2009
    Messages:
    742
    [edit] Never mind, me dumb.
     
    Last edited: Jul 16, 2012
  13. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    hoMove's HOTween Tweener is named "tween", stored as a private variable. You can access its timeScale property via tween.timeScale = ...; There is no built-in method in hoMove for controlling the timescale at this point.

    edit: mkay :)
     
  14. c-Row

    c-Row

    Member

    Joined:
    Nov 10, 2009
    Messages:
    742
    Yes, I just didn't figure out until I noticed tween was set private rather than public. Thanks anyway. :)

    Seems like I need two Tweeners since I can't seem to reverse the myTSTween once it has completed, though. Maybe I just forward this particular issue to Izitmee since the SWS part of my scene works fine. ;)
     
    Last edited: Jul 16, 2012
  15. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,417
    Answered on HOTween's thread: no two Tweeners needed! :D (sorry, I should've mentioned the AutoKill behaviour while giving you the "scrub" idea)
     
  16. chaneya

    chaneya

    Member

    Joined:
    Jan 12, 2010
    Messages:
    112
    Just in case anyone is interested, I needed to use SWS in a menu screen while the game was paused using Time.timescale = 0f;

    As far as I can tell, there is no way to access that iTween feature within SWS. (iTween has a command called ignoretimescale) that allows you to bypass timescale specifically in cases where you may want to use an iTween during game pause, for menus etc.)

    The iMove script seemed to be the best place to put a public variable that would allow this. This also lets me control this on a per gameobject basis. So I can have some waypoint objects adhere to timescale and others not.

    At the top of iMove.cs, I placed:
    public bool ignoreTimeScale = false;

    then in the Move method in iMove.cs, I simply added another itweenHash.Add statement as follows:
    iTweenHash.Add("ignoretimescale", ignoreTimeScale);
    Then I just set the bool to true in the inspector on that object and it works great.

    This takes advantage of the built in feature in iTween "ignoretimescale" and adds it to the hash used by your gameobject with the iMove script.

    Allan
     
  17. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    Hi Allan,

    you're right, there is no ignoretimescale option in SWS.
    I intentionally programmed iMove as it is, since I can't add checkboxes for all features of iTween.
    Glad you found out where it belongs and thanks for sharing!

    B.
     
  18. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    Version 2.1 is ready! And has been submitted to the Asset Store.

    If you haven't bought Simple Waypoint System yet, now you can also purchase it through our online store,
    which sends you a generic download link at the time of purchase, that always points to the latest version.

    [​IMG]


    I'm really excited for this release, because now your objects can actually leave their paths!
    I implemented a new settings field for custom messages, so you are able to program every possible interaction or behavior at a waypoint. You could stop the movement at a waypoint, turn on Unity's pathfinding or let the object look around, move it back to the waypoint and continue its path. The list goes on!

    [​IMG]

    Here is the complete changelog.

    Fixes Changes

    • hoMove: removed critical waypoint distance value that led to unexpected behavior when tweening an object with a very high speed value or timescale
    • hoMove: completely rewritten to incorporate with partial tweens. The tween and its runtime checks should be a significant amount faster now
    • hoMove: partial tweens allow easing options between waypoints instead of an easing curve for the whole path
    • hoMove: separated MoveToPath and its internal ClosePath option, you can toggle them independently now as ClosePath has its own checkbox
    • hoMove: movement parameters (waypoint positions) do not update at each iteration anymore, you have to call InitWaypoints() and recreate the tween manually with StartMove(), for example at the last waypoint using messages
    • simplified the Waypoint Manager even more, it shows only one button now
    • switched widget position. You’ll find the Waypoint Manager setup widget under “Window > Simple Waypoint System” and iMove/hoMove under “Component > Simple Waypoint System”
    • documentation updated, contact info email changed​
    Features

    • iMove/hoMove: custom methods callable per waypoint. Both editor scripts for iMove/hoMove were changed accordingly, so that this feature comes with a new message settings field, easily adjustable by the user
    • custom methods are using SendMessage() and allow one parameter of the type object, text, numeric, vector2 or vector3. The class of these types was centrally placed in WaypointManager.cs
    • new example script “MessageExample.cs” demonstrates the usage of custom messages in the scene “Example_Straight” on walker “Capsule4”
    • hoMove: integrated HOTween’s new lock-position option that limits movement on the selected axis​


    A special thanks goes to Daniele and his incredible work on HOTween, without whom this update would not have been possible.
     
  19. cel

    cel

    New Member

    Joined:
    Feb 15, 2011
    Messages:
    24
    brilliant... would love to see this implemented into playmaker....
     
  20. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,417
    Wow, awesome list of additions! It's impressive how SWS grew in just a few weeks: if that's not awesome support I don't know how to call it. Plus, I know I might appear as an Inspector maniac, but the new and improved waypoint Inspector looks so sexy!

    That said, very special thanks to you for supporting HOTween :)
     
  21. anwserman

    anwserman

    New Member

    Joined:
    Feb 13, 2012
    Messages:
    36
    Hey Baroni -
    I purchased SWS but haven't had the opportunity to use it yet. What I'd like to do with it (eventually) is have it control vehicles within my game. I've done this before in other languages, but the visual structure of SWS I hope will make things easier to do at design time.

    Anyway, let's say I have four paths - A, B, C, D. When the object hits the last waypoint of Path A, I'd like for the object to randomly choose from path B, C, or D to continue on it's way. Think of a four-way intersection, and a car can choose from turning left, right, and forward (but still has to move between the last waypoint of the previous path and the first waypoint of the new path).

    Any assistance or guidance with this would be fantastic!
     
  22. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    @cel

    playmaker support is on my list for version 2.2. I don't know how to do it yet, because I've never used it and I'm a programmer, but let's see how to handle this... "visual thing".

    @Izitmee/Daniele

    Good to hear that you like the new inspector setting! Had to struggle with the design and unexpected GUI errors almost 2 days :D Btw, your copy has left the building.
     
  23. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    Hi anwserman,

    this behavior should be easy to program with the newly implemented message settings. What you want to do first, is to write a small method, attach the script to your vehicle and assign the created method to the last waypoint in the message settings of that vehicle. Now your vehicle should call an empty method at its last waypoint.
    Next, you have to choose a path (B, C, or D) in that method. You could hardcode the path names in a string array and randomly choose one slot. Then, call the vehicle's SetPath() method (you need a reference to iMove/hoMove) with the corresponding PathManager parameter like this:

    Code (csharp):
    1. iMove/hoMove-script.SetPath(WaypointManager.Paths["the name of your chosen path here"])
    Depending on your use case, make sure that you set the variable "MoveToPath" of iMove/hoMove to true before calling SetPath(). This will ensure that your vehicle moves to the path before following its waypoints.

    Please let me know if you need further help.

    Greetings,
    Baroni
     
  24. Lars Steenhoff

    Lars Steenhoff

    Member

    Joined:
    Aug 7, 2007
    Messages:
    874
    @Baroni Playmaker actions are very welcome! Thanks
     
  25. anwserman

    anwserman

    New Member

    Joined:
    Feb 13, 2012
    Messages:
    36
    Hey Baroni!

    Thanks for your reply! Anyway, I've always just had the vehicles decide when to accelerate or decelerate, they alone never chose paths. If they'd go to a traffic light, the vehicle would randomly get a new path if the light was green or brake if red. This could be easily implemented via triggers. But knowing that this new feature enables movement between paths is great.

    Since we're on the topic, do objects on a path have tge option of rotating with the path, and if so how does aligning to the ground work with such a feature?

    Thanks a lot!
     
  26. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    Hi anwserman,

    just a small hint on the first line: you can control the speed of a tween using its timescale property (described on the HOTween docs).

    Rotating with the path is an option built-in long time ago :) There's a checkbox in the inspector for iMove/hoMove named "Orient To Path". Regarding the second issue: per default, your object will follow the height of each waypoint, that means if you align the waypoint to the ground, your vehicle will simply follow it. The "Size To Add" value in the inspector adds an additional height to the car (typically you type in the half of your object's height), so the vehicle "stands" on the path. There's also a selectable field "Lock Rotation" to lock the rotation on one axis so it does not tilt to a side. Unfortunately there is no built in setting that allows rotation around a corner (to lift the wheels) and uneven terrain is a bit critical, but maybe I misunderstood what you want to achieve?

    Regards,
    B.
     
  27. anwserman

    anwserman

    New Member

    Joined:
    Feb 13, 2012
    Messages:
    36
    I think I got it - I'm currently implementing the core gameplay right now (what's the point of having vehicles running around if the main aspect of gameplay isn't implemented?!?). I'll take a break from working on my game input (and backing it up!) and start trying with SWS.

    Basically, I would like the vehicle to rotate on the X/Y axis and ignore the Z axis. So the vehicle will slope forward/backward when going up hills and turn left/right when turning, but NOT bank on the z-axis.

    -Jeff

    EDIT: Baroni, I found a bug in SWS! I'm so sorry! I'll re-edit and post a video once I get one uploaded.

    Anyway, here's what happens, Scenario 1:
    1) Object is moving between paths (using the Move to Path feature)
    2) Object's speed is set to 0, object keeps moving to the first node of the new path and then stops


    Anyway, here's what happens, Scenario 2:
    1) Object is moving between paths (using the Move to Path feature)
    2) Object's speed is set to 0
    3) iMove.Stop() is called
    4) Object stops
    .... some time passes ...
    4) Object's speed is set higher than zero (let's say 6)
    5) iMove.StartMove() is called
    6) Object moves at a snail's pace (even though the speed value says 6) until it hits first node, then moves normally

    Here's a video that I made:
    http://www.youtube.com/watch?v=wooeKIJkXZ0

    EDIT: I think I know what the problem is now. iTween's speed only gets updated at checkpoints - if you change it between checkpoints, it saves it for updating later.... is that by design?...

    The cube at the bottom left represents the stages of the stop light system so far! :D
     
    Last edited: Jul 29, 2012
  28. nielsvaes

    nielsvaes

    Member

    Joined:
    Jul 29, 2012
    Messages:
    17
    I seem to be having a bit of a problem playing an idle animation... or maybe I'm just doing it wrong. I want my character to pause for 5 seconds at waypoint 1. However, I always get an error message saying that the idle (or any other) animation can't be found. I can select it just fine in the the Inspector, but it doesn't want to play. All my animations are different FBX files containing the skeleton of the main character doing different things, is that the problem?

    https://dl.dropbox.com/u/332384/Capture.JPG
     
  29. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    Hey Jeff,

    thanks for recording a video! You're right, iTween updates its parameters (speed value) only at every waypoint, there is no way to change parameters of a running ( i- ) tween. That's an iTween thing. I suggest you use the hoMove component for smooth movement of your vehicles. hoMove utilizes HOTween behind the back and allows curved paths since version 2.0.

    As mentioned above, you can get the tween of hoMove (declare the "tween" variable as public first) and control the speed using its timescale property. This would get rid of scenario 1, because if the timescale of the tween is zero, the tween does not run further. You could also call Pause() and Resume() on the hoMove component to achieve the same result.

    That would be very similiar to scenario 2, where Pause() and Resume() could stop and resume the tween at the stop light. (nice colorful box btw :) ) Again, using the timescale property and perhaps a coroutine for acceleration and deceleration could give a desired result. Let me know your progress on this.
     
  30. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    Hi nielsvaes,

    no, that should not be a problem, thanks for the screencapture. By investigating your object, "Gerrit Mover" has no animation component attached, that's fine. But the animation clips have to be assigned to an object, does the gameobject "Character_Gerrit" have these animation clips assigned like at this page? http://docs.unity3d.com/Documentation/Components/class-Animation.html

    If yes, please expand the FBX animation file and try to directly drag the animation clip in the "Idle Anim" slot instead.
    Hope that helps,

    Regards,
    B.
     
  31. anwserman

    anwserman

    New Member

    Joined:
    Feb 13, 2012
    Messages:
    36
    I looked into HoTween and I figured out that I can't use tweening at all, unless my mental math is wrong (I've been hammering it hard the last few days hah). There's no simple way of doing it, by changing a normalized timescale value between 0-1 means that the vehicle will move at a speed dependent on the space between checkpoints.

    Instead, what I did is figured out how you implemented your checkpoint system ;) I took the difference in position between checkpoint(n) and checkpoint(n + 1), normalized it, and move any gameobject on it by gameobject.transform += (differenceVector * speed * time.deltatime). For rotation between points, I use iTween's LookTo feature.

    If you're interested, I'll clean up and comment my code and post it - or send it to you! If you like it, I'd love to clean it up and send it to you as a package. I have it designed to where you can drag a script onto an object and it starts tweening (like yours) but also an additional script that when trigger boxes collide, will assign a new path to a tween or change it's state - like braking.
     
  32. c-Row

    c-Row

    Member

    Joined:
    Nov 10, 2009
    Messages:
    742
    I don't know if I fully understand what you are trying to do, but I did a small test project using timescale settings in HOTween to brake/accelerate a vehicle a week or two ago just fine. I set the SWS tween to speed instead of time to avoid speed differences when moving between checkpoints. Have you tried to use speed instead of time?
     
  33. anwserman

    anwserman

    New Member

    Joined:
    Feb 13, 2012
    Messages:
    36
    Yeah, I used speed instead of time, still the same problem (except it went around curves). The speed also didn't change until it went to a new checkpoint, which I found odd. But anyway, I still got it working (regardless), so the point's still moot lol.
     
  34. nielsvaes

    nielsvaes

    Member

    Joined:
    Jul 29, 2012
    Messages:
    17
    I just opened this page to let you know I found the problem, didn't expect a reply so soon :) Anyway, you were right, I scaled the animations array of Character_Gerrit down to just 1, which held the walk animation.

    Thanks for the prompt reply though!
     
  35. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    That seems uber complicated :)

    Could you pm me your package and a short explanation on what you are trying to do?
    Maybe I'll get it running without math, as c-Row confirmed. Complicated code isn't the best way in the long run.
     
  36. nielsvaes

    nielsvaes

    Member

    Joined:
    Jul 29, 2012
    Messages:
    17
    I'm still a little bit foggy about this. Where do you need to add these methods in order execute these? Can you place them anywhere? Do you need specific scripts with specific names in specific locations?

    In our game, we want to have the character walk from waypoint1 to waypoint 5. He needs to stop at waypoint3 and a specific animation needs to play there. Once that animation is done, the character needs to continue to waypoint 5.

    How exactly do I need to set this up? Let's say I have an animation called "dancing". Do I just need a script with

    Code (csharp):
    1.  
    2. void StartDancing()
    3. {
    4.     animation.Play("dancing");
    5. }
    6.  
    7.  
    and then use "StartDancing" as a method name on waypoint 3?
     
  37. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    It's nearly as simple as that ;) You can look up a message sample in the scene "Example_Straight", where a capsule flies through the air.
    From the changelog:
    Basically you create a script and attach it to your walker object. Name it whatever you like. Then you create a method within this script, let's call it "StartDancing" as in your post. At the desired waypoint, type in the name of this method in the message settings.

    Regarding the method: In this case, you want to pause the tween at the third waypoint, play the animation and resume the tween after the animation fully played through. There are two different approaches for pausing a tween, depending on the movement script. For iMove, you would use:

    Code (csharp):
    1. public AnimationClip danceClip;
    2.  
    3. IEnumerator StartDancing()
    4. {
    5.   iMove-script.Stop();
    6.   animation.Play(danceClip.name);
    7.   yield return new WaitForSeconds(danceClip.length);
    8.   iMove-script.StartMove();
    9. }
    For hoMove, you would use Pause() and Resume() instead of Stop() and StartMove().
    Should be pretty straight forward :)
     
    Last edited: Jul 30, 2012
  38. nielsvaes

    nielsvaes

    Member

    Joined:
    Jul 29, 2012
    Messages:
    17
    Again, thanks for the swift replies.

    I'm not trying to be an idiot, but I just am :) That, and it's been a long time since I've done any programming in Unity. The problem I'm having right now is this:

    [​IMG]

    Code (csharp):
    1. hoMove-script
    is not recognized. Do I need to define or include anything before I can use it?
     
  39. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    You need a reference to the hoMove component:

    Code (csharp):
    1. private hoMove hoScript;
    2.  
    3. void Start()
    4. {
    5.   hoScript = gameObject.GetComponent<hoMove>();
    6. }
    Now you can use hoScript.Pause() and every other public method of the hoMove script for this walker object in your "DoingStuff" function.
     
  40. nielsvaes

    nielsvaes

    Member

    Joined:
    Jul 29, 2012
    Messages:
    17
    Great, got it working now.

    Thanks for the great support, we're going to use your system for our new game so you'll have at least a couple more sales because we're going to use it on every machine here :)
     
  41. wmgcata

    wmgcata

    Member

    Joined:
    Jul 20, 2012
    Messages:
    169
    Before i'm going to buy this package i've got one question first.

    Does this system automatically puts the character on the right Y-axis? Or could you give me a little more information about the moving object/character placement?

    Thanks in advance
     
  42. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    Wonderful, you're welcome :)
     
  43. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    Hi wmgcata,

    it puts the character on the path you created in the editor. The path could be 2D, 3D with Y-up, Z-up or something else.
    The first thing you would do is to create a path in your scene. Then, you rotate your object how you need it to be and attach a movement script to it. It will then simply follow the path assigned to it. There are no limitations regarding world axes. Did I answer your question?

    edit: the rotation of the object would stay the same on the whole path. If you need your object to rotate while moving on the path (maybe climbing a wall), there can be a bit of scripting involved.

    Greetings
     
    Last edited: Jul 30, 2012
  44. anwserman

    anwserman

    New Member

    Joined:
    Feb 13, 2012
    Messages:
    36
    Hahaha, it's not really that bad. I'll message it to you when I get the chance - I've actually coded this before in other languages, and this is the first time I got it working in less than an hour! :D Before, it would take multiple days if not weeks to get it done =)
     
  45. anwserman

    anwserman

    New Member

    Joined:
    Feb 13, 2012
    Messages:
    36
    Hey Baroni,

    Here is my code for moving vehicles, like I said I'd post =)

    Code (csharp):
    1.  
    2. [RequireComponent (typeof (Collider))]
    3. public class VehicleControllerScript : MonoBehaviour {
    4.     public float accelerationSpeed;
    5.     public float decelerationSpeed;
    6.     public float maxSpeed;
    7.     public float minSpeed;
    8.     public float turnSpeed;
    9.     public bool  loopPath;
    10.     public int startingTargetPoint;
    11.     private float baseSpeed;
    12.    
    13.     private VehicleTriggerScript vTrigger;
    14.     private bool  assignedPath;
    15.        
    16.     public enum Enum_Vehicle_State
    17.     {
    18.         GO = 1,
    19.         BRAKE = 0
    20.     }
    21.    
    22.     public Enum_Vehicle_State vehicleState;
    23.    
    24.     //rem let's see if we can use the iMove framework to make our own pat system
    25.     //rem hold waypoints
    26.     private Transform[] waypoints;
    27.     //rem hold what point we are currently at
    28.     private int currentPoint;
    29.     private Vector3 basePoint;
    30.     public PathManager startPath;
    31.     private Vector3 vectorDiff;
    32.     private float oldDist;
    33.     private float newDist;
    34.    
    35.     void  Start (){
    36.         waypoints = startPath.waypoints;
    37.         vectorDiff = new Vector3();
    38.        
    39.         currentPoint = startingTargetPoint;
    40.         UpdateCarDirection();
    41.     }
    42.    
    43.     void  Update (){
    44.             if (vehicleState == Enum_Vehicle_State.GO)
    45.                 {
    46.                     baseSpeed += (Time.deltaTime * accelerationSpeed);
    47.            
    48.                     if (baseSpeed > maxSpeed)
    49.                         baseSpeed = maxSpeed;
    50.                 }
    51.                
    52.             if (vehicleState == Enum_Vehicle_State.BRAKE)
    53.                 {
    54.                     baseSpeed -= (Time.deltaTime * decelerationSpeed);
    55.            
    56.                     if (baseSpeed <= minSpeed)
    57.                         baseSpeed = minSpeed;
    58.                 }          
    59.            
    60.             gameObject.transform.position += vectorDiff * baseSpeed * Time.deltaTime;
    61.            
    62.             oldDist = newDist;
    63.             newDist = Vector3.Distance(gameObject.transform.position, waypoints[currentPoint].position);
    64.            
    65.             if (newDist > oldDist)
    66.                 {
    67.                 gameObject.transform.position = waypoints[currentPoint].position;
    68.                 currentPoint += 1;
    69.                 UpdateCarDirection();
    70.                 }
    71.         }
    72.        
    73.     void  OnTriggerEnter (  Collider other   ){
    74.         vTrigger = other.gameObject.GetComponent<VehicleTriggerScript>();
    75.         AssignNewPath();
    76.     }
    77.    
    78.     void  OnTriggerStay (){
    79.         AssignNewPath();
    80.         }
    81.        
    82.     void  OnTriggerExit (){
    83.             vehicleState = Enum_Vehicle_State.GO;
    84.             assignedPath = false;
    85.             vTrigger = null;
    86.         }
    87.        
    88.     public void  AssignNewPath (){
    89.        
    90.         if (vTrigger != null)
    91.         {
    92.             if ((vTrigger.canAssignPath)(vTrigger.possiblePaths.Length > 0))
    93.                 {
    94.                     if ((assignedPath == false)((vehicleState == Enum_Vehicle_State.GO)||(vTrigger.forcePath)))
    95.                         {
    96.                             //imComp.speed = accelerationSpeed;
    97.                             baseSpeed = accelerationSpeed;
    98.                             assignedPath = true;
    99.                             int tInt;
    100.                             tInt = Random.Range(0, vTrigger.possiblePaths.Length);
    101.    
    102.                             //rem get waypoints
    103.                             waypoints = vTrigger.possiblePaths[tInt].waypoints;    
    104.                             currentPoint = 0;
    105.                            
    106.                             if (vTrigger.moveToPath == false)
    107.                             {
    108.                                 gameObject.transform.position = waypoints[currentPoint].position;
    109.                                     currentPoint += 1
    110.                                     iTween.LookTo(gameObject, waypoints[currentPoint].transform.position, 0.1f);
    111.                
    112.                             }
    113.                                    
    114.                             UpdateCarDirection();      
    115.                         }
    116.                 }
    117.            
    118.        
    119.         }
    120.        
    121.            
    122.     }
    123.  
    124.        
    125.     public void  UpdateCarDirection (){
    126.    
    127.         if (currentPoint == waypoints.Length)
    128.             {
    129.                 if (loopPath == true)
    130.                     {
    131.                         currentPoint = 0;
    132.                     } else {
    133.                         vectorDiff = new Vector3();
    134.                     }
    135.             }
    136.            
    137.             if (currentPoint < waypoints.Length)
    138.             {
    139.                 vectorDiff.x = waypoints[currentPoint].transform.position.x - gameObject.transform.position.x;
    140.                 vectorDiff.y = waypoints[currentPoint].transform.position.y - gameObject.transform.position.y;
    141.                 vectorDiff.z = waypoints[currentPoint].transform.position.z - gameObject.transform.position.z;
    142.                
    143.                 vectorDiff.Normalize();
    144.                
    145.                 iTween.LookTo(gameObject, waypoints[currentPoint].transform.position, turnSpeed);
    146.             }
    147.        
    148.         oldDist = Vector3.Distance(gameObject.transform.position, waypoints[currentPoint].transform.position);
    149.         newDist = oldDist;
    150.     }
    151.  
    152.    
    153.     public void  SetVehicleState ( Enum_Vehicle_State pState  ){
    154.             vehicleState = pState;
    155.         }
    156.    
    157. }
     
  46. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    @anwserman
    I'll look into it in a free minute :)


    Version 2.1.1 has hit the Asset Store. This version fixes smaller bugs and introduces several custom PlayMaker actions (thanks to Alex Chouls from Hutong Games for a developer copy). I don't know if these actions are useful at all, please let me know what you are trying to do and whether you need more or other actions.


    V 2.1.1

    Fixes Changes
    • hoMove: fixed Pause() so it actually does pause the tween correctly
    • hoMove: fixed bug on “closePath” not playing a walk animation while moving
    • MessageExample.cs: added methods for pausing a tween with messages
    • HOTween: updated to version 1.1.333, big thanks to Daniele who fixed the constrained rotation using “lockAxis” and improved “lookAhead” rotation, also optimized partial tweens and made them more garbage collector friendly ​

    Features
    • PlayMaker actions: added SWS_SetPath, SWS_GetPathNode, SWS_SetPathNode under “Simple Waypoint System” in the Action Browser (unzip the archive file)​
     
  47. cel

    cel

    New Member

    Joined:
    Feb 15, 2011
    Messages:
    24
    Brilliant....

    Just a few requests for the playmaker actions... could we get and "every frame" option on the get path action.... I'm trying to change paths but to the same index of the other path...

    Also, a pause/ stop action?

    and if possible, change speed at runtime... trying to add/subtract speed with two keys as an object moves trough a path...

    Again, fantastic addition to sws...

    keep up the excellent work
     
  48. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    So you want that your object moves e.g. to the third waypoint of the new path and continues there? That would be easier with iMove, but nearly uneffective with hoMove as it always generates the whole path at start.

    Pause() and Stop() don't require parameters, you can use SendMessage for these.

    I'll try to get these implemented soon.

    Thanks :)
     
  49. pinchmass

    pinchmass

    Member

    Joined:
    Jul 2, 2012
    Messages:
    91
    Another quick one, is their a simple way to change the speed at runtime (from Javascript) so I can speed up and slow down my character (thinking of a running gaming with all this olympic stuff).

    It would also be great to change the speed of the animation at the same time
     
  50. Baroni

    Baroni

    Member

    Joined:
    Aug 20, 2010
    Messages:
    1,032
    In iTween, there's only the possibility to change the speed once, not over time. This was discussed back on page 2. Changing the speed of an animation is described here and here, unfortunately there is no built-in method at this time.

    As for HOTween, you can use its timescale property for changing its playback speed.

    Code (csharp):
    1. public void ChangeSpeed(float value)
    2. {
    3.     // create another HOTween to change the timescale to 'value' over 3 seconds
    4.     HOTween.To (tween, 3, new TweenParms().Prop("timeScale", value);
    5.  
    6.     //animate animation speed over time (in this case over 3 seconds)
    7.     if (anim == null) return;
    8.     foreach (AnimationState state in anim)
    9.     {
    10.         HOTween.To(state, 3, new TweenParms().Prop("speed", value));
    11.     }
    12. }
    13.  
    I don't know how to effectively convert this to unityscript, but you can add this to hoMove.cs and call it via SendMessage() or, if the scripts are located in the Standard Assets folder, get the component via unityscript and directly call the method. Hope that helps!