- Home /
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
Answer by Legend_Bacon · Dec 12, 2017 at 09:08 AM
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
good idea! I'm also realizing I should probably leave the boulder's mass untouched and just increase the mass of my character.. that way the boulder's mass will remain accurate if something else hits it too, but I'm not 100% sure if it will work since I haven't tested increasing character mass before (fairly new to this)
$$anonymous$$aking it kinematic might be a good way to make sure absolutely nothing moves the boulder as well! Thanks!
Your answer
Follow this Question
Related Questions
Object not moving,Object not moving in any direction 1 Answer
Quaternions acting up 1 Answer
Flinging Wall Death 1 Answer
Change Movespeed based on Mouse Input 0 Answers