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

    La prensa creó al nuevo Messi y ahora castiga a Lamine Yamal por no serlo

    Lamine Yamal no es Messi, ni Cristiano Ronaldo, ni Mbappé: el problema no es su fútbol, sino las expectativas que han creado sobre él Hoy parece que le toca recibir…

    Nadie apostaba por el Real Madrid, pero Mourinho volvió a dar una lección de fútbol

    El Real Madrid vuelve a demostrar que nunca se le puede dar por muerto, Mourinho ganó la batalla al Barcelona Ayer el Real Madrid volvió a demostrar por qué es…

    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

    La prensa creó al nuevo Messi y ahora castiga a Lamine Yamal por no serlo

    • Por admin
    • octubre 26, 2026
    • 52 views
    La prensa creó al nuevo Messi y ahora castiga a Lamine Yamal por no serlo

    Nadie apostaba por el Real Madrid, pero Mourinho volvió a dar una lección de fútbol

    • Por admin
    • octubre 26, 2026
    • 56 views
    Nadie apostaba por el Real Madrid, pero Mourinho volvió a dar una lección de fútbol

    El Barça juega mejor, pero el Real Madrid de Mourinho nunca debe darse por muerto

    • Por admin
    • octubre 24, 2026
    • 44 views
    El Barça juega mejor, pero el Real Madrid de Mourinho nunca debe darse por muerto

    Real Madrid y Barcelona ganan entre polémicas: ¿es esta la Liga que queremos?

    • Por admin
    • octubre 20, 2026
    • 58 views
    Real Madrid y Barcelona ganan entre polémicas: ¿es esta la Liga que queremos?

    El Real Madrid remonta a la Roma, pero sigue sin convencer: ¿tiene Vinícius los días contados?

    • Por admin
    • octubre 15, 2026
    • 95 views
    El Real Madrid remonta a la Roma, pero sigue sin convencer: ¿tiene Vinícius los días contados?

    El Barça está por encima de Messi, señor Gaspart, pero su historia más gloriosa lleva su nombre

    • Por admin
    • octubre 13, 2026
    • 72 views
    El Barça está por encima de Messi, señor Gaspart, pero su historia más gloriosa lleva su nombre