- Home /
Using a collider to define the boundary of a level?
I am working on an underwater game where the user pilots a submarine around an underwater world. I would like to create an invisible spherical wall around the important part of my level, so that the user can't leave the area (though they can see terrain extending beyond it) I thought I could do this by just putting a giant spherical collider on a null game object centered in the level. Unfortunately, the spherical collider seams to assume that other colliders should always remain outside of it, and will force rigid bodies with colliders outside of the sphere. Is there a way to create a spherical collider that will instead contain colliders, and prevent them from leaving?
Thanks,
-Matt
Answer by Chris D · Jun 17, 2011 at 08:12 PM
I think your options may be limited here...here's something to try, though:
Model your level boundary (correct size) in a modeling program (eg. blender)
ensure your normals are flipped
import to unity and use a mesh collider
The caveat being that I'm not entirely sure how unity generates mesh colliders on import (I'm assuming from surface normals).
good one. I am always thinking in mobile game terms. And if it is not a mobile game, this should work just as you wanted $$anonymous$$att.
Ah, nice - wasn't quite sure about it, but seemed like it should work.
Brilliant. Just tried it out, and it works peachy keen. Thanks Chris!
PS. I'm not working on a mobile game, but do I infer from Anxo's comment that mesh colliders don't work in mobile? Thats good to know for future ref.
No, I'm pretty sure they work on mobile. I think the concern was more one of performance (as using a mesh collider is kind of expensive to use), but I could be wrong.
Gotcha. So it might be better to use a simpler mesh with fewer faces in mobile? A low poly cylinder or cube. I may change $$anonymous$$e to a cylinder anyway now that I'm going with a mesh.
Answer by Anxo · Jun 17, 2011 at 08:13 PM
Hi mat, you can set the spherical collider to trigger. Then you can ad a
OnTriggerExit function to the player so that something happens when they try to leave. If want them to run into a wall you will have to build a box out of 6 boxes. I dont think you can invert a collider.
Answer by tstpierre_nss · Nov 22, 2012 at 03:25 AM
Here is another solution that we released today on the asset store.
It allows quick create of complex boundaries for a level.