- Home /
changing gravity for one object.
so i have a car in my game..... and i want it to have more gravity then other objects.
i have tried using
rigidbody.AddForce(0,-25,0);
but it does not work.. and i have tried the constant force component but it has the same results.
what happens is it moves down really slowly even when i have it set to -25 or something.
i have tried disabling the car script but it does the same thing.
so i thought that it might be something to do with the wheel colliders....
any thought on how to fix this would be nice.....
thanks
Answer by Edy · Aug 16, 2010 at 11:24 PM
Function FixedUpdate()
{
rigidbody.AddForce(Physics.gravity * rigidbody.mass);
}
This means 2g for that rigidbody. Moreover, if now you disable rigidbody's "Use Gravity" you'll get the normal 1g results.
Answer by Novodantis 1 · Aug 05, 2010 at 07:05 PM
Two quick things you can check:
Physics is affected by scale. A person jumping off a building takes longer to hit the ground than a lego man falling off a box at the same relative scale. If your scale is huge, it will make your physics appear in slow motion. Check how many units your car is long (ideally 4 or thereabouts).
Time step / Time Scale. Both found under Settings -> Time. They will affect the overall speed of your simulation, but it's worth playing around with these and the forces applied to your car.
Have you tried altering global gravity anyway? What undesirable behaviour (if any) does it cause elsewhere?
well i have tried the global gravity but it made everything go to fast but i think the only thing that needs to be faster is the car..... the timeScale is set to 1 and the timeStep is set to 0.02.... and everything is the right scale EG main character is 2 meters tall the car is scaled relative to the player.
It is odd how AddForce in the $$anonymous$$us y doesn't make a difference. What's the mass of the car? You might also want to try changing the force mode of that force, and Debug.Log out the line after to make sure it's being applied. You can check up Force $$anonymous$$odes here: http://unity3d.com/support/documentation/ScriptReference/Force$$anonymous$$ode.html
Why even bring up Global gravity??? Don't you know that Global gravity affects all objects???
The question is about affecting the gravity of one object, not all objects. $$anonymous$$ass should do that but Unity didn't make that so, which is a stupid mistake on their part. Ins$$anonymous$$d we are stuck with all objects falling at the same (Global gravity) speed, no matter what.
Answer by Tuah · Nov 29, 2010 at 08:09 PM
ForceMode.Force (default) incorporates mass, so you'd have to multiply the force by mass to make it work like gravity.
ForceMode.Acceleration works regardless of mass, just like real gravity. This is what Rigidbodies use when UseGravity is checked.
Answer by ghost20000 · Jun 28, 2015 at 10:11 PM
Just change the mass of the car's rigidbody, it should be slower...