- Home /
RigidBody2D Constant Velocity?
Hello, I am making a game where you have to avoid falling blocks. The game is 2D and the objects are squared. The objects seem to fall perfectly fine using Gravity, but the blocks that spawn higher up gain too much speed falling down which ends up making my game near impossible. I have tried searching for other posts but none seem to work for me. All help is appreciated.
Did you try a search on "unity limit rigidbody speed"? The first thing that came up is the way I do it.
You say that none work for you? Which ones? $$anonymous$$aybe you're just missing one thing.
Answer by DanSuperGP · Feb 06, 2015 at 10:39 PM
Gravity works like... gravity.
That is, it's an acceleration, 9.8 meters per second, per second.
So, if you want your falling blocks to travel at a constant velocity instead of accelerate, you will need to turn gravity off, and then set a velocity for the rigid body.
You can set the velocity of a rigidbody directly.
http://docs.unity3d.com/ScriptReference/Rigidbody2D-velocity.html
Of course, if you have drag (and you should have some) and you set their velocity once, they will slow down.
But you could just set the velocity every frame in Update.
Answer by lienadnellum · Feb 07, 2015 at 02:27 AM
Hi I had the same problem. The speed at which it falls is velocity I believe.this is how to access the speed at which it falls "rigidbody2D.velocity.y" so this might help.Just make this a Java Script attach it to a block give it physics 2d set all the values on the component to zero,on the script ,Set max falling speed to the fastest you want the block to fall, set the falling speed increase to how fast you want it to gain speed.
/*"var Velocity : Vector2;// helps for debugging
var MaxFallingSpeed : float = -10;
var FallingSpeedIncrease : float = .1;//how fast to make the object fall faster.
function Start () {
GravityEffect();
} function GravityEffect () {
var i = 1;
for(i=1;i>0;i++){
yield WaitForSeconds(FallingSpeedIncrease);
if(rigidbody2D.velocity.y > MaxFallingSpeed){
rigidbody2D.velocity.y -= .1;
}
}
}
function Update () {
Velocity = rigidbody2D.velocity; //this will give the velocity in the y and x values constantly
}"*/
Answer by SUPPEAR · Feb 06, 2015 at 11:12 PM
I just ended up with deciding to put an angular drag on. When I said it didn't work for me, I meant it as in the objects went through the objects. Thanks for the response though :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613182658im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Destroy Object On Touch? 2D 1 Answer
Destroy Object On Touch? 4 Answers
big terrain performance && mobile 1 Answer
Touches not registering in android? 0 Answers
iOS and Android Publishing 2 Answers