- Home /
How to make objects collide and move each other?
I am trying to make an object move when I walk into it. I want the object to fall off a cliff if I push it off. I appreciate the help. Thanks.
Answer by Tuck · Jan 10, 2011 at 06:19 AM
Add a rigidbody to the object you want to move. Click the using gravity button on the rigidbody component. Attach a class to the object that checks on collision enter if the collider is the player, and then add a force to the rigidbody equal to the player's transform.forward times how hard you want to push it. That will get a accurate-ish pushing effect.
Answer by Proclyon · Jan 10, 2011 at 08:59 AM
You could use a script that reacts to a collision with the player. Just go for the OnCollisionStay function/method or OnCollisionEnter function/method. This is just the event though , once you have the event you will still have to play some animation or use force by adding rigidbody like Tuck suggested and physically push an object around.
You could also Use the collision event + an input manager key to make it move when standing next to it and pressing some sort of use key, this should prevent the mistake of just wanting to stand next to it but due to the collision it falls off. That depends on what you are aiming for of course.