- Home /
How to Set Gravity to a specific Object?
I saw CharacterMotor but isn't there a built in way to set the gravity of a specific object, lets say a sphere without gravity and all the other object has gravity? The object needs to be dynamic too not kenematic. Basically I wanted to make a sidescroller airplane that I can move. Also can there be different Physics configuration to different objects?
Answer by DaveA · Mar 26, 2013 at 04:28 PM
If it has a RigidBody, you can turn off gravity on that.
I am using Lerpz from 2D Tutorial. and it has no rigidbody. I have tried to attach a RigidBody Component to my character and unchecked the use gravity and still doesn't work. Thanks a lot for your quick responses.
Answer by whydoidoit · Mar 26, 2013 at 04:32 PM
You can't set gravity for a specific object - I wish I could do that in the real world, but PhysX like the real world doesn't allow it!
You can apply a constant force to an object to keep it in the air though, which you can use to specify your own gravity:
public Vector3 gravityForThisObject;
void OnFixedUpdate()
{
rigidbody.AddForce((gravityForThisObject-Physics.gravity) * rigidbody.mass);
}
I am using Lerpz from 2D Tutorial. and it has no rigidbody. I have tried to attach a RigidBody Component to my character and unchecked the use gravity and still doesn't work. Thanks a lot for your quick responses.