Forum rules - please read before posting.

Follow Path, reverse direction?

edited August 2021 in Technical Q&A

Hello,

I'm using follow path for a mini game , where the player can start/stop a vehicle.
1. I want to add the possible to making the vehicle reverse - without turning around, just moving backwards instead along the path?
2. I want to add the possibility to "dodge" things on the track, so turning left or right - I added markers to both sides of the vehicle and made them parent to the vehicle so they follow around and be used to "offset" the vehicle i relation to the path. I cant seem to get it to do what I want - any other creatives ideas maybe?

Any direction would be much appreciated
Best, Dan

Comments

  • So the vehicle itself is an AC character?

    I want to add the possible to making the vehicle reverse - without turning around, just moving backwards instead along the path?

    If you move the vehicle's model to a child object of the character, you can set it's rotation independently of its root.

    What does the path look like? Straight, so that the direction is fixed, or curved? Screens of the setup will help understand the situation.

    I want to add the possibility to "dodge" things on the track, so turning left or right

    Adding Markers either side could work. If you move the vehicle itself to a child object as above, you can then have these Markers beside it in the Hierarchy, and then use e.g. Object: Transform to have the vehicle model move sideways.

  • Hi Chris .
    Yes, the vehicle has an NPC component attached and then teleported to a path that has a circular shape (obviously with very sharp corners) with a path type of "loop".
    It can however only move forward and stop(Using Character: Move along path and the methods stop and resume. Is there a way to during gameplay, instead of vehicle going from node 0 to 1 - to ie go from 1 to 0 so I can make the vehicle reverse?
    (ie similar to a train moving: I want the loop type going forward - but during gameplay I want to train to be able to reverse)

    I'm also wondering : does object: Transform (using translate in this case) not work when having an animator with a controller assigned to the object?
    I made a little animation with a "turn" anim and using play custom animation when dodging (otherwise having an idle running)- however the translate will only work if the the animator controller isn't assigned.

    Thanks a lot!
    Best, Dan

  • Is there a way to during gameplay, instead of vehicle going from node 0 to 1 - to ie go from 1 to 0 so I can make the vehicle reverse?

    The v1.74.0 update provides a dedicated Player: Lock to Path Action that allows for moving in both directions along a Path.

    If the Path is turning, and you want to remain facing the direction of the Path, you'll need a custom script that affects rotation based on which nodes the character is currently in-between. Something along these lines:

    using UnityEngine;
    using AC;
    
    public class FaceForwardPath : MonoBehaviour
    {
    
        public Transform transformToAffect;
        public Char characterOnPath;
        public float lerpSpeed = 3f;
    
        private void LateUpdate ()
        {
            Paths path = characterOnPath.GetPath ();
            if (path == null)
            {
                return;
            }
    
            int targetNode = characterOnPath.GetTargetNode ();
            int previousNode = characterOnPath.GetPreviousNode ();
    
            if (targetNode < previousNode)
            {
                int tempNode = targetNode;
                targetNode = previousNode;
                previousNode = tempNode;
            }
    
            Vector3 thisLineDirection = (path.nodes[targetNode] - path.nodes[previousNode]).normalized;
            transformToAffect.eulerAngles = Vector3.Lerp (transformToAffect.eulerAngles, thisLineDirection, Time.deltaTime * lerpSpeed);
        }
    
    }
    

    does object: Transform (using translate in this case) not work when having an animator with a controller assigned to the object?

    Only if the Animator also affects the object's position. As above, I recommend separating things in your hierarchy (i.e. moving your model to a child object) so that you can control the position of your root and model independently.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.