Simple as the title, instead of increasing the gravity in the settings, is there a way I can define the gravity through JS for a specefic object? Like have an integer variable that I can adjust and depending on that variable will depends the object’s gravity. Can’t figure it out personally. Right now I am using RigidBody on my car, and it is light as a feather.
(The reason I ask for per object instead of overall setting) is because inside a script I want a gravity function that I can adjust according to different vehicles I make.
All you basically need to do is adding additional forces to the rigidbody. The physics engine will automatically consider the additional forces and calculate the correct motion/velocity.
As it is a influence on physics, it should be done in FixedUpdate just like:
public class gravityController : MonoBehaviour {
public float counterGravity = 9.81f;
void FixedUpdate()
{
rigidbody.AddForce(new Vector3(0,counterGravity,0));
}
}
If the counterGravity is set to the opposite of the global setting, the object will act as if it is not influenced by gravity anymore because both forces … [missing the correct word for it, sorry] the force will just equalize the gravity force. :S