How to make a cylinder collider inside a cylinder
Hi All!
So I'm making a game where the user is moving through a tunnel, which is a long cylinder. But I can't seem to find a way to stop him from moving through the tunnel walls. What collider should I be using, and would it work stopping him from going from inside to outside?
Thanks!
Hyper.
Answer by alphadogware · Jan 25, 2018 at 11:21 AM
There is a simple solution to this, although not pretty.
You can simulate this collider by the following:
1. creating a box collider around your object
2. then create another empty gameobject inside your object
3. then add another box collider to that empty game object
4. rotate the gameobject 45 degrees, which will turn the new box collider
5. repeat as necessary for effect
I did it for a wine glass and it worked fine.
A year later, but still on point. This is exactly what I did! I used about 16 boxes to make the entire circles, and it works well.
Did you have any issues with the oncollisionenter being called too many times? I had to setup a variable that held the delta time for oncollision calls. This is because I was playing a sound on oncollision enter and it was being called too many times cause of all of the extra colliders.
Funny you mention that, I did have issues with triggers. But then I just disabled them all together and just used the boxes as walls to stop the user. I did have sounds attached to them, but it just went crazy so I just gave up on that idea! So you just had some kind of bool isPlaying = true to check when the audio is playing so it doesn't play again until another collision?
Answer by chum10 · Nov 18, 2016 at 11:57 AM
You have to use a mesh collider with the normals facing inwards.
I don't think you can unless you are building the mesh procedurally. The easiest way would be to create that mesh collider in your favourite 3D modelling software.
$$anonymous$$akes sense. I made the tunnel cylinder in a 3D software, and the normals are facing inwards because the texture of the tunnel is inside the tunnel in Unity. Which means I can just use the same cylinder, just add a mesh collider to it? I tried this, and having a collider on the player, and I still just go through the walls.
Your answer
![](https://koobas.hobune.stream/wayback/20220612100919im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How To Ignore A Tag 1 Answer
Trigger is not detecting tag 2 Answers
C# bool active when player collides with object 1 Answer
VRChat Player falls through floor regardless of colliders 0 Answers
2D Character Falling Through Ground 0 Answers