Forum rules - please read before posting.

Making a treadmill in first person, AC

Hello, I'm a bit of a newcomer in adventure creator and in unity. I'm having trouble making a treadmill or moving walkway script (something that will constantly push the player along a given (1,0,0) axis) in 3d, first person.
What i have right now is this:

using AC;
using UnityEngine;

public class MovingWalkway : MonoBehaviour
{
public Vector3 movementDirection = new Vector3(1, 0, 0); // Move along X-axis
[SerializeField] float speed = 5f; // Adjust speed in Inspector

private void OnTriggerStay(Collider other)
{
    if (other.CompareTag("Player")) // Check if the object is the player
    {
        KickStarter.player.transform.position += movementDirection.normalized * speed * Time.deltaTime;
    }
}

}

From what I have right now, the player moves along the path only when it is standing still. I cannot seem to get the variable for the player position that is constantly updating(?). Any suggestions on how to go about this?

Thank you.

Comments

  • Welcome to the community, @blob1.

    The exact way AC handles its character motion is down to your Player settings and attached components - could you share screenshots to show their setup?

    Generally though, you can try moving them in LateUpdate - using the Trigger functions to keep track of the Player's presence. Try this:

    using AC;
    using UnityEngine;
    
    public class MovingWalkway : MonoBehaviour
    {
        public Vector3 movementDirection = new Vector3(1, 0, 0);
        public float speed = 5f;
        bool affectPlayer;
    
        private void OnTriggerEnter (Collider other)
        {
            if (other.CompareTag("Player"))
            {
                affectPlayer = true;
            }
        }
    
        private void OnTriggerExit (Collider other)
        {
            if (other.CompareTag("Player"))
            {
                affectPlayer = false;
            }
        }
    
        private void LateUpdate ()
        {
            if (affectPlayer)
            {
                KickStarter.player.transform.position += movementDirection.normalized * speed * Time.deltaTime;
            }
        }
    
    }
    
  • Thank you for the solution. This works perfectly :)

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.