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;
    private float Velocidad;

    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);

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

        if (movementDirection !=
            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


3 comentarios

  1. Very good write-up. y absolutely apreciate this site. quep writing!

  2. Thanks for one’s marvelous posting! y actually enjoyed reading it, you are

    a greate author.i wil be sure to bokmark your blog and wil often come back later in life.

    y wante to encourage yourself to continue your greate

    job, ave a nice evening!

  3. 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 un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *