- Home /
Constant force
Hey guys i was just wondering how to change the constant force gravity on an object on collision
Answer by Ludiares.du · Sep 30, 2011 at 06:00 PM
var hit = false;
function OnCollisionEnter(collider : Collision)
{
hit = true;
}
function Update()
{
if(hit)
{
rigidbody.AddForce(transform.forward * 10 * Time.deltaTime)
}
}
Answer by SilverTabby · Sep 30, 2011 at 06:09 PM
There are two ways to change the gravity affecting an object:
You can change the Physics.gravity constant to affect all objects or you can add gravity by hand
Editing Physics.gravity is simple (see the doc link) but affects EVERYTHING
To apply a diffrent gravity to this object, have a script that does the following:
rigidbody.useGravity = false;
Holds a
var localGrav : Vector3 = Vector3.up * -9.8;//down 9.8 m/(s*s) is earth's gravity
- Inside of LateUpdate,
[rigidbody.AddForce][3]( localGrav, [ForceMode][4].Acceleration );
Now just change localGrav and your rigidbody will move at a localized, custom gravity amount
[3]: http://unity3d.com/support/documentation/ScriptReference/Rigidbody.AddForce.html
[4]: http://unity3d.com/support/documentation/ScriptReference/ForceMode.html
Your answer
Follow this Question
Related Questions
Gravity not functioning properly? 1 Answer
How do I make a small planet with gravitational pull? 4 Answers
gravity problem 1 Answer
Vector3 and power 1 Answer