Hello! I’m working on a game for a game jam, and need some help. It’s set in space, and I’d like a big part of the game to be leaving your spaceship, going into zero-gravity, and collecting space junk. However, I’m having some trouble getting gravity to turn on and off upon entry and exit to the spaceship. I’m trying to make use of the Rigidbody.useGravity function with the following code, which is applied to the spaceship.
// Enables gravity on all rigidbodies entering this collider.
void OnTriggerEnter(Collider other)
{
if (other.attachedRigidbody)
other.attachedRigidbody.useGravity = true;
}
// Disables gravity on all rigidbodies entering this collider
private void OnTriggerExit(Collider other)
{
if(other.attachedRigidbody)
other.attachedRigidbody.useGravity = false;
}
------------------ Code End -------------------------------------------------
However, when I’m in play mode and moving my character around, the “Use Gravity” toggle in the Rigidbody component is not checking on and off as I exit and enter the spaceship’s collider. Any ideas of what I’ve done wrong? Thank you!