Hi, I asked about making a treadmill or a moving walkway in the past. Over the period, I had to move the script component from the object to the player. More importantly however, I have encountered a problem where the player is pushed along the intended direction only when there is no movement input. Is there a way for the player to be pushed regardless of player movement? Thank you
using AC;
using UnityEngine;
public class MovingWalkway : MonoBehaviour
{
public Vector3 movementDirection = new Vector3(1, 0, 0);
public float speed = 5f;
private bool affectPlayer;
private void OnTriggerEnter(Collider other)
{
Debug.Log("Entered: " + other.name);
if (other.CompareTag("Obstacle"))
{
affectPlayer = true;
}
}
private void OnTriggerExit(Collider other)
{
Debug.Log("Exited: " + other.name);
if (other.CompareTag("Obstacle"))
{
affectPlayer = false;
}
}
private void OnTriggerStay(Collider other)
{
if (affectPlayer)
{
Vector3 localMovementDirection = other.transform.TransformDirection(movementDirection.normalized);
// Convert to local direction of the walkway
transform.position += localMovementDirection * speed * Time.fixedDeltaTime;
// Move the player in direction
}
}
}
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Is this with the default First-person Player prefab? Try affecting ther CharacterController instead of the Transform:
Yes it was. Thank you, its working perfectly