I'm new to C# and Unity. I need to normalize the velocity of my player, but only in the x-direction. My current code is
void Update ()
{
if(rb2d.velocity.magnitude > maxSpeed)
{
rb2d.velocity = rb2d.velocity.normalized * maxSpeed;
}
This controls all velocity. I tried
void Update ()
{
if(rb2d.velocity.x.magnitude > maxSpeed)
{
rb2d.velocity.x = rb2d.velocity.x.normalized * maxSpeed;
}
But I think this was removed in Unity 5. What can I do?