- Home /
Curved 3d Collider
In my game I am using splines to create rails that the player can grind on.
The problem I have is that each rail needs one long, continuous collider that spans the whole length of the rail.
For short, or relatively straight rails, I just have to place one box collider that covers the whole rail, but If I want to use curved rails, I would need to use multiple colliders, which would dismount the player as they leave one collider and my OnTriggerExit() function is called.
I've been trying to use the EdgeCollider2d collider instead, as you can configure the points to create one curved collider, but I have been having trouble setting it up in my scenes.
Is there a way I can create a 3d curved collider for each of my rails?
Or alternately, is there a way that I could write a OnNotTriggerStay() command? -So that I can just place box colliders along my rail as per usual.
Please don't link me to other questions, I've already done lots of research.
Thanks! All help is appreciated!
Answer by tanoshimi · Nov 16, 2016 at 02:35 PM
You simply need a mesh collider that uses the same curved rail mesh as you use for your renderer: https://docs.unity3d.com/Manual/class-MeshCollider.html
Hm. This would be quite hard as the player can also grind on some of the level's geometry. So the mesh collider I would access would be the same collider as the entire level's. Detaching the geometry itself for each level would also be more work than it's worth.
But the idea of using a mesh collider is pretty promising. Any chance I can 'generate' a mesh for my spline? it would be difficult, sure, but It would make adding rails, and letting my users make their own rails, super easy!
Sure - you can programmatically create a mesh for the mesh collider from your spline by specifying each vertex and triangle, exactly the same way as you'd create a procedural mesh for rendering. https://docs.unity3d.com/$$anonymous$$anual/Example-CreatingaBillboardPlane.html
Your answer
Follow this Question
Related Questions
How do I create AI with a good side and evil side? 0 Answers
Does OnTriggerStay don't detect a collision with a non-trigger collider? 1 Answer
How do I use colliders and/or triggers to end the game? 1 Answer
OnTriggerEnter Multiple Collisions Activating. I tried many variations, Please help (Java) 3 Answers
changing gravity OnTriggerEnter 1 Answer