- Home /
Question by
cemberke61 · Jul 25, 2018 at 02:02 PM ·
c#unity 5unityeditor
How do I make a 2D cars face the direction it is moving like drifting,How do I make a 2D object face the direction it is moving like drifting
As you guys seen in the picture I have a 2 gameObject the car is following the circle. The circle is moving with the cursor. Currently, my car is following the circle from a distance but ı want that, when the circle moves along the X-axis ı want to rotate my car like it's drifting. Here is my car fallow script.
public class Follow : MonoBehaviour
{
public Transform leader;
public float followSharpness = 0.1f;
Vector3 _followOffset;
void Start()
{
// Cache the initial offset at time of load/spawn:
_followOffset = transform.position - leader.position;
}
void LateUpdate()
{
// Apply that offset to get a target position.
Vector3 targetPosition = leader.position + _followOffset;
//GetComponent<Rigidbody2D>().rotation = 1.5f;
// Keep our y position unchanged.
//targetPosition.y = transform.position.y;
// Smooth follow.
transform.position += (targetPosition - transform.position) * followSharpness;
}
}
screenshot-2.png
(3.4 kB)
Comment