- Home /
Character Controller collision box too large?
Hi there, I am making a Tetris-style game, and for some reason when I place the blocks they are hanging just above the platform that I place them on. Is this the box collider or the character controller? I don't know.
A screenshot of the scene with the colliders visible would help, but indeed it seems that the colliders are too big, what happens if you make them smaller?
That's weird, the collider looks O$$anonymous$$.! If you shrink it by half what happens? I suggest shrinking by 1% over and over until you get the right kind of contact. But it's unusual that they have that gap around them, maybe something else is going on. I made a test project with just 2 cubes and added a Rigidbody and BoxCollider and they overlap just right (the offset is there so you can see where each cube ends).
Hmm... First, I'm using a character controller, not a rigidbody, and second, shrinking is by half is the same.
Answer by florianveltman · May 29, 2015 at 02:35 PM
Though I would generally disagree with the use of a character controller in this situation (I don't know the whys and wherefores of your project but a character controller seems way overkill for a tetris-style game), an easy, temporary fix might perhaps be to check the character controller's height and radius. Maybe try to reduce its size to be a magnitude smaller than the collider to see how it behaves.
In any case, both the character controller and the collider prevent the object from going through the other, so one of them is probably redundant.
Does the collision with BoxCollider still work if I use transform.Translate()? I'm kind of a noob at Unity, so I don't know. The only reason I was using a CharacterController was because I knew that definitely checked for collisions. I didn't want to use a Rigidbody because I thought it would be a bit too unstable. So, would this still work with OnControllerColliderHit?
Collisions actually only ever occur with physics, with the character controller being the exception. It's indeed a good idea to use the character controller for collisions if there are no physics involved in the game, but since your project seems to actually be about collisions between the boxes, it'll be better to use Rigidbodies, which will be better optimised for multiple moving parts that need to collide.
The correct way to move a Rigidbody is to use AddForce(), ins$$anonymous$$d of transform.translate. It pretty much works the same way, but it informs the engine that you are effectively moving a Rigidbody around. If you want to use transform.translate, you should make the Rigidbodies kinematic — but this will disable the possibility of detecting collisions. OnControllerColliderHit() is indeed for the character controller, ins$$anonymous$$d you can use OnCollisionEnter(). Note that you can also constrain a Rigidbody's position and rotation on various axes, this might come in handy when using Rigidbodies without gravity.
If you however really want to avoid using physics for some reason, you might want to have your blocks move on a grid of valid positions. This will enable you to use OnTriggerEnter(); you could make the box colliders a little bigger than the actual boxes, and when the trigger fires, have the manipulated box snap to a certain position.
Hope that helps!
Your answer
Follow this Question
Related Questions
Box collider with character controller? 0 Answers
how to disable the character controller and box collider for after hitting the character controller 1 Answer
Charcter won't go through Box Collider!! Need Help asap! 1 Answer
OnColliderStay does not work 1 Answer
Character's trigger collides with itself 2 Answers