Make GameObject only move when conditions are fulfilled

Hey Guys-

I’m making a game (3D) where I want my character to only be able to move an object with a rigidbody only when certain conditions are fulfilled.

Here are the objects in my scene:

  • A player with a character controller
  • A boulder with a rigidbody and mesh collider
  • a ground plane with collider

Right now I have something like this on my player :

public enum States {normal, superStrong};

I was thinking something like this might work:

if (playerState == superStrong){
Boulder.GetComponent<RigidBody>().Mass = 1;}
else {Boulder.GetComponent<RigidBody>().Mass = 100;}

This works, but the problem is, the RigidBody of the boulder weighs less universally (so if another rigidbody were to collide with it, it’s mass would not be proportional) Does anyone know if there is a better way to do this? Maybe if I make the characterController mass larger? I’m not sure

Hello there,

instead of changing the boulder’s mass, you could set it to be kinematic. As long as it is, it should ignore all forces applied to it, thus becoming static. Then you can just turn it off again when your player meets the conditions.

I hope that helps!

~LegendBacon