I found some code online for a simple 2D car movement script. However, I want to understand WHY it works the way it does so I can make tweaks to it. I’m particularly confused with ‘GetRelativeVector’:
float direction = Vector2.Dot(rb.velocity, rb.GetRelativeVector(Vector2.up));
if(direction >= 0.0f) {
rb.rotation += h * steering * (rb.velocity.magnitude / 5.0f);
//rb.AddTorque((h * steering) * (rb.velocity.magnitude / 10.0f));
} else {
rb.rotation -= h * steering * (rb.velocity.magnitude / 5.0f);
//rb.AddTorque((-h * steering) * (rb.velocity.magnitude / 10.0f));
(where ‘rb’ is an instance of Rigidbody2D).
Here’s what the manual says:
As far as I can tell, Vector2.up is just synonymous to a simple vector (0,1). And this vector is the ‘local space vector’ argument. So what would rb.GetRelativeVector(Vector2.up) be?