Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Simple Waypoint System (SWS) - Move objects along paths

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

  1. SIV

    SIV

    Joined:
    May 7, 2014
    Posts:
    216
    Hmm, i think it could be done using the loop for.
     
  2. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,646
    @SIV I'm not sure what exactly you are trying to do, I've just mentioned two ways - the Reverse() method which works at runtime on a running tween, or the startPoint approach which indeed tells the object to go straight to that waypoint. You can implement a combination of both things, or others from the Scripting Reference (e.g. set the "reverse" flag to true before calling StartMove() again), depending on your exact needs.
     
  3. SIV

    SIV

    Joined:
    May 7, 2014
    Posts:
    216
    Ok thank you, im gonna play with that for a bit.
     
  4. Lucideus

    Lucideus

    Joined:
    Dec 7, 2015
    Posts:
    12
    Does locking the Z-rotation work for anyone in Unity 2020.3.32f1 or similar?
    I've tried this asset, Bezier Curves, DoTween and none of them seem to be able to lock the Z-rotation properly. The only way I've found possible to actually do this is creating a separate script that forces the z-eulerangle to remain 0 otherwise it does absolutely nothing when moving along a spline.
     
  5. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,646
    Hi @Lucideus, the human walkers in the sample scenes all use Z-rotation locks to not tilt sideways. You can check this by trying to modify their Z-rotation in the inspector at runtime - it will stay at 0. This is done by setting the "Lock Rotation" dropdown to X, since in global rotation, the Z value rotates around the X axis.
     
  6. Lucideus

    Lucideus

    Joined:
    Dec 7, 2015
    Posts:
    12
    Hmm, I'm not sure I follow.

    Here is an image of my problem. The top image is when I don't run a custom script on the Model-child of the enemy ship, and I set the Lock Rotation to "X" in the Spline Move component. It doesn't face in the spline direction properly. Setting it to lock Z does nothing, though.
    To better explain it, I have enemies spawn in from a random direction, in this case from the top of the screen. Once they line up and go straight forward (towards the player) though they don't rotate upwards properly, they stay "turned" on the Z-axis.

    The bottom image is when I run my custom script that I've attached to the child instead that contains the model itself.
    Code (CSharp):
    1. public class LockRotation : MonoBehaviour
    2. {
    3.     public Transform ParentTransform;
    4.  
    5.     void Update()
    6.     {
    7.         if (ParentTransform.rotation.z != 0)
    8.             this.transform.eulerAngles = new Vector3(
    9.                 ParentTransform.rotation.eulerAngles.x,
    10.                 ParentTransform.rotation.eulerAngles.y,
    11.                 0);
    12.     }
    13. }
    That's the full code for it. That does what I want it to (bottom image). Here, once they line up they no longer stay turned on the Z axis.

    Edit: Made some gifs to clarify it a bit better perhaps:
    Spline Move Lock Z Rotation: https://imgur.com/i4OkkEQ
    Spline Move Lock X Rotation: https://imgur.com/axZXa0P
    Custom Lock (script above): https://imgur.com/Y204YR9
     
    Last edited: Jun 28, 2022
  7. Lucideus

    Lucideus

    Joined:
    Dec 7, 2015
    Posts:
    12
    As a separate question; is there a way to get the distance of a spline, or between certain waypoints along the spline? (including any curves and such) Thanks!
     
  8. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,646
    @Lucideus thanks for the gifs. Still difficult to tell, but there does not seem to be much difference between X rotation and your custom lock script, except for the beginning of the path when the objects fly down. The issue and why X rotation does not work as expected could be caused by a default rotation on the model, unexpected turns of the path (where DOTween still tries to force a path alignment), or another splineMove setting. Again, very difficult to tell based on screenshots - if you've solved by using your custom script and are happy with the result, that's fine! If not, just know that I am available to look at it directly, if you could send me a repro package via PM.

    Yes: if you only need a rough estimate on the full path length for information or further calculation, you can find it when selecting the PathManager in the inspector. The path length value is displayed in the upper part, however this does not take curves into account.
    For the exact length including curves (like it is displayed in the scene) you can call the static method WaypointManager.GetCurved instead, by passing in the path waypoints and then handing the result over to WaypointManager.GetPathLength which does the distance calculation.
     
  9. Lucideus

    Lucideus

    Joined:
    Dec 7, 2015
    Posts:
    12
    Fair enough! So far I've not run into any real issues with my solution so I'll stick to that for the time being.
    Thank you for the help (regarding the waypoint-distance also)! :)
     
unityunity