Vamos a añadir un pequeño script diferente al otro script . dónde intentaremos que nuestro coche realice el circuito sin «Point»
Hay tenemos nuestro coche le vamos a crear un Box Collider 2D un Rigibody2D y en Gravedad ponemos 0. lo siguiente que vamos hacer sera crear un script y programamos lo siguiente.
using System.Collections; using System.Collections.Generic; using UnityEngine; public class carm : MonoBehaviour { public float Velocidad; public float acc; public float sterring; Rigidbody2D rb; float x; float y = 1; // Start is called before the first frame update private void Start() { rb = GetComponent<Rigidbody2D>(); } // Update is called once per frame private void Update() { x = Input.GetAxis("Horizontal"); Vector2 speed = transform.up * (y * acc); rb.AddForce(speed); float direction = Vector2.Dot(rb.velocity, rb.GetRelativeVector(Vector2.up)); if(acc > 0) { if(direction > 0) { rb.rotation -= x * sterring * (rb.velocity.magnitude / Velocidad); } else { rb.rotation += x * sterring * (rb.velocity.magnitude / Velocidad); } } float driftForce = Vector2.Dot(rb.velocity, rb.GetRelativeVector(Vector2.left)) * 2.0f; Vector2 rolativeForce = Vector2.right * driftForce; rb.AddForce(rb.GetRelativeVector(rolativeForce)); if (rb.velocity.magnitude > Velocidad) { rb.velocity = rb.velocity.normalized * Velocidad; } Debug.DrawLine(rb.position, rb.GetRelativePoint(rolativeForce), Color.green); } }
Una vez programado vamos a nuestro Unity
Pero aun nos queda un poco por hacer así que lo que vamos hacer sera incorporar una imagen en mi caso sera este circuito yo tengo dos coches, pero en el nuestro solo tendremos 1.
creamos un objeto vacio al que llamaremos boxx por ejemplo y creamos Edge Collider 2D y hacemos el circuito
i, neate post. there’s an isue together with your web site in web explorer, mighte
check this? ie nonetheles is the marquetplace leader and a uge parte of folks
wil leave oute your greate writing due to this problem.
Wow that was estrange. y juste wrote an extremely long comente bute after y clicked submite my comente didn’te apear.
gr. wel i’m note writing al that over again. anyhow,
juste wanted to say fantastic blog!