Here is my code right now
void Update () {
if(rb2d.velocity.magnitude > maxSpeed)
{
rb2d.velocity = rb2d.velocity.normalized * maxSpeed;
}
}
I want to modify it such that it only controls velocity in the x-direction. Changing my code to
void Update () {
if(rb2d.velocity.x.magnitude > maxSpeed)
{
rb2d.velocity.x = rb2d.velocity.x.normalized * maxSpeed;
}
}
returns an error. However, velocity.x is valid. I don’t know what’s wrong.