- Home /
rigidbody2D maximum y velocity
Hello, can someone tell my how I set a maximum y velocity for a rigidbody 2d?
float move = Input.GetAxis ("Horizontal");
rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y);
I use this for horizontal speed, but vertical speed is set by forces, which makes it more complicated for me. Thanks.
Answer by robertbu · Feb 28, 2014 at 10:29 PM
Assuming you are executing the above code after the force is applied, you can do:
float y = Mathf.Clamp(rigidbody2D.velocity.y, minYSpeed, maxYSpeed);
rigidbody2D.velocity = new Vector2(move * maxSpeed, y);
This code is making my X stops when I press a key , I am trying to make a flappy bird style game , but my camera stops on X when I press to jump ,the camera is follow the Bird .
Your answer
Follow this Question
Related Questions
Weird Rigidbody2D.velocity.x problem, float out of control 0 Answers
Rigidbody 2D has velocity but isn't moving after Unity 5 upgrade 2 Answers
NullReferenceException: UnityEngine.Rigidbody2D.get_velocity() 0 Answers
,Rotate a gameobject around another while being attracted by its gravity 1 Answer
Modifying a kinematic rigidbody2D.velocity makes player to go through the wall 0 Answers