- Home /
Collision detection not working
I've got a cube with a player controller script attached, then I have multiple collision boxes with the cube as the parent object at points around the cube. My enviroment is also made up of cubes each with a collision box attached. What I am trying to do is see which of the collision boxes attached to my player has hit one of the other collision boxes outside of my player. Ie. the cube has 4 collision boxes, one on each 4 sides of the cube, if the front collision box has hit a collision box of another game object then do function. This is what I have so far. bcBottom is attached to the cube whilst floorBc is attached to the outside gameobject I am trying to create a collision between. If it has hit it then fwdMove = true, if not then it's false however it is never coming back as true only ever false.
void OnColliderEnter(Collider bcBottom) {
if (bcBottom.gameObject.tag == "floorBc") {
fwdMove = true;
}
}
void Update () {
if (Input.GetButtonDown ("VerticalFwd")) {
if(fwdMove == true){
amountToMove.y = 1f;
transform.Translate (amountToMove);
} else {
fwdMove = false;
}
}
}
Answer by flaviusxvii · Dec 15, 2013 at 10:32 PM
OnColliderEnter should be OnCollisionEnter.
I realised that after I posted however it still makes no difference. Am I going some where wrong stupidly simple? If the boxcollider attached to the player is bcBottom and I want to check that it is hitting the collider with the tag floorBc. Is this the way I would go about it? Bare in $$anonymous$$d there are multiple box colliders attached to the player object.
I don't know enough about everything you have set up. Double check you have colliders attached to everything you want to collide.
I'm getting really confused here now after playing around trying to get this to work. Say I had a cube with no box collider but it had 4 box colliders attached to emptygameobjects, 1 on each of the cubes faces and they are within the cube as children so the cube is their parent. Each collider is tagged 1, 2, 3, 4 retrospectivley. If I wanted to check that collider 1 has hit another collider completely seperate of the player, say it was tagged as colliderEnviroment. Also none of the colliders have rigid bodies, how would I check that box collider 1 has hit that collider? When I'm searching for help I can only find help for instances where there is only 1 collider attached the to player directly and not as a child object. I'm getting pretty confused right now :/ Thanks for the help so far.
Your answer
![](https://koobas.hobune.stream/wayback/20220613124238im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity Collison Problem 1 Answer
front check based on unity projects not working. 0 Answers
how do i correctly use a box collider 1 Answer
Enemy Detection Area 1 Answer
C# GameObject is not detecting collision with Character Controller 2 Answers