alli te va Galletito otro para que lo termines esta vez con dos modos de 3D:
codigo base:
public class PlayerController : MonoBehaviour
{
public float speed = 5f;
public float rotationSpeed = 700f;
private CharacterController controller;
private Vector3 moveDirection;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
Vector3 direction = new Vector3(horizontal, 0, vertical).normalized;
if (direction.magnitude >= 0.1f)
{
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0, targetAngle, 0);
moveDirection = direction * speed;
}
moveDirection.y += Physics.gravity.y * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}
public class NPCController : MonoBehaviour
{
public Transform[] waypoints;
private NavMeshAgent agent;
private int currentWaypoint = 0;
void Start()
{
agent = GetComponent<NavMeshAgent>();
agent.destination = waypoints[currentWaypoint].position;
}
void Update()
{
if (!agent.pathPending && agent.remainingDistance < 0.5f)
{
currentWaypoint = (currentWaypoint + 1) % waypoints.Length;
agent.destination = waypoints[currentWaypoint].position;
}
}
}