- Home /
Change rigidbody's jumping speed
Hello,
i make a 2d gave and the player is a rigidbody. I use "rigidbody.AddForce(0,300,0)" to make him jump, but I want him to stay less time on air. Like he makes a small vurve from ground to air. In other words I want the falling speed to increase.
How can I do this?
Answer by robertbu · Jul 24, 2013 at 08:32 PM
Possible solutions:
You can increase gravity. Go to Edit/Project Settings/Physics. Edit -9.81 to some stronger value. Note you'll have to increase your force applied in AddForce() to get the same height of jump.
You can replace gravity by your own force either in your script, or you can use the Constant Force component.
You can add a single burst of force when the object turns around as @highpockets suggests.
You could apply (or augment gravity) with a constant force only when the object is dropping. You can use Rigidbody.velocity and apply the force only when the 'y' value is negative.
Answer by highpockets · Jul 24, 2013 at 08:06 PM
track the y position like this:
Vector2 lastPos;
bool movingDown`= false;
void Update()'
if( lastPos.y > transform.position.y `&& movingDown = false`)
{
rigidbody.AddForce(0,-300,0);
movingDown = true;
}
lastPos = transform.position;
So when your y position is lower than the last frame you will start to add force downwards.
Are you sure that falling speed will be the same between 20fps and 200fps?