Movimiento simple de nuestro coche

Aquí lo que vamos hacer es un movimiento simple de nuestro coche, durante la carrera

 

Aquí tenemos nuestro coche,  ahora os voy a enseñar los componentes que le tengo asignado,

 

a mi coche le tengo asignado un Box Collider2D un Nav Mesh Agent, y el Script.. ahora os enseñare el Script

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;


public class Movimientodelcoche : MonoBehaviour
{
    private NavMeshAgent agent;
    [SerializeField]
    private float Velocidad;

    [SerializeField]
    private float Rotaciondelcar;




    // Start is called before the first frame update
    void Start()
    {

        agent = GetComponent<NavMeshAgent>();

        agent.autoBraking = false;
    }



    // Update is called once per frame
    void Update()
    {

        transform.rotation *= Quaternion.Euler(+90, 0, 0);
        float horizontalInput = Input.GetAxis("Horizontal");

        float verticalInput = Input.GetAxis("Vertical");

        Vector2 movementDirection = new Vector2(horizontalInput, verticalInput);
        float inputMagnitude = Mathf.Clamp01(movementDirection.magnitude);
        movementDirection.Normalize();

        transform.position -= -transform.up * Velocidad * Time.deltaTime;

        if (movementDirection != Vector2.zero)
        {
            Quaternion toRotation = Quaternion.LookRotation(Vector3.forward, movementDirection);
            transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, Rotaciondelcar * Time.deltaTime);
        }


    }
}

este código seria el que utilizaría en mi coche, Pero para hacer todo esto tenemos que tener NavMesh

 

  • Related Posts

    Messi después del Mundial: la historia de un campeón que siguió intentando tocar el cielo

    Lionel Messi: la historia del niño que tuvo que perder muchas veces antes de tocar el cielo La historia de Lionel Messi no es solamente la historia de uno de…

    No fue el Mundial de Lamine Yamal: Rodri se convirtió en el verdadero líder de España

    España volvió a tocar el cielo y se proclamó campeona del mundo en 2026. Antes de comenzar el torneo, muchas miradas estaban puestas en Lamine Yamal. Por edad, talento, repercusión…

    One thought on “Movimiento simple de nuestro coche

    1. Unquestionably consider that which you stated. Your favorite
      justification seemed to be on the web the easiest thing to consider of.
      I say to you, I definitely get irked at the same time as other folks think about worries that they
      plainly do not realize about. You controlled
      to hit the nail upon the top and also outlined out the entire thing
      without having side-effects , people could take a signal.
      Will probably be again to get more. Thanks

    Deja una respuesta

    You Missed

    Messi después del Mundial: la historia de un campeón que siguió intentando tocar el cielo

    • Por admin
    • julio 27, 2026
    • 13 views
    Messi después del Mundial: la historia de un campeón que siguió intentando tocar el cielo

    Argentina no perdió por un complot: España fue mejor y hay que aceptarlo

    • Por admin
    • julio 24, 2026
    • 23 views
    Argentina no perdió por un complot: España fue mejor y hay que aceptarlo

    No fue el Mundial de Lamine Yamal: Rodri se convirtió en el verdadero líder de España

    • Por admin
    • julio 23, 2026
    • 30 views
    No fue el Mundial de Lamine Yamal: Rodri se convirtió en el verdadero líder de España

    Jugadores que ganaron el Mundial antes de los 20 años: la lista histórica

    • Por admin
    • julio 22, 2026
    • 39 views
    Jugadores que ganaron el Mundial antes de los 20 años: la lista histórica

    Mbappé vs Lamine Yamal: ¿quién es mejor?

    • Por admin
    • julio 21, 2026
    • 48 views
    Mbappé vs Lamine Yamal: ¿quién es mejor?

    Lamine Yamal 2026: ¿El nuevo rey del fútbol mundial?

    • Por admin
    • julio 21, 2026
    • 36 views
    Lamine Yamal 2026: ¿El nuevo rey del fútbol mundial?