- Home /
Question by
shaibam · Jul 15, 2015 at 09:20 AM ·
gravity2d-physicsaxisforcerelative movement
Limit speed on x axis when applying force with gravity
I have a 2dSprite with rigidbody2d gravity.
when pressing the "down" key, I constant relative force.
I want to limit the speed of the sprite, this works great when the movement is only on the Y axis (rotation=0).
But when the sprite has a rotation, the gravity makes it fall down.
Code:
void FixedUpdate () {
float MAX_SPEED = 3;
if (Input.GetKey ("down")) {
Vector2 power_vector = new Vector2(0,0.5f);
if (r_2d.velocity.magnitude<MAX_SPEED)
ApplyRelativeForce (power_vector, ForceMode2D.Impulse);
}
}
Suggestions?
Comment
Your answer
Follow this Question
Related Questions
Gravity doesn't work 2 Answers
Horizontal attraction? 0 Answers
Gravity keeps my player from moving 1 Answer
How can I calculate the force required to contradict gravity?2d 2 Answers
2D Objects interacting with colliders and gravity seemingly at random 0 Answers