- Home /
Collision Problem - Floor Button & Character Controller
Hey guys,
I'm currently developing puzzle game, where the floor has trap buttons. I have tried most of the collision methods to detect when the player object (character controller) is over the trap button. The trap button is a cube and it cannot detect when the player is over, does anyone know how to fix this or have an alternative solution?
Note: (1). The cube does have collider. (2). The character controller does detect the cube, but I want the cube to detect the player.
Thanks for the help guys, appreciate it!
Hi clunk, I've tried that as well, that's still not working out for me. I'll play around with it again tomorrow, brain dead now :(
Answer by TheRichardGamer · Oct 26, 2013 at 10:23 AM
So, you want to make a empty game object with a collider that is going to be a trigger by clicking "Is Trigger" and then add a script with this code:
var PlayerIsOn = false;
function Update () {
if(PlayerIsOn == true){
//Your Code here
}
}
function OnTriggerEnter (Other : Collider) {
if(Other.gameObject.tag == "Player"){
PlayerIsOn = true;
}
}
function OnTriggerExit (Other : Collider) {
if(Other.gameObject.tag == "Player"){
PlayerIsOn = false;
}
}
NOTE: TAG YOUR PLAYER TO "Player" OR ELSE IT WON'T WORK.
NOTE: YOU MUST ATTACH THIS EMPTY GAME OBJECT TO YOUR BUTTON GAME OBJECT.
Hi Richard, I've tried your method now and it worked like a charm! Thank you!
Your answer
Follow this Question
Related Questions
Help Understanding Raycast 2 Answers
Unity3d Arm collision 1 Answer
Pixel Perfection collision on 3d animated object 0 Answers
Find axis of collision 0 Answers