- Home /
How would I prevent ghost vertices?
My tile-based platformer has a box collider2d assigned to each tile. My character also has a box collider2d. My character occasionally gets stuck on the vertices of some tiles. These are called ghost vertices. How would I prevent this?
You should specify more. $$anonymous$$aybe add some images or video.
Do you use physical movement or do you manipulate the transform. From my experience manipulating the transform works better when having problems with ghost Vertices.
Answer by Munchy2007 · Jun 26, 2016 at 07:23 PM
Using edge colliders instead of box colliders will solve the problem, this thread discusses it. http://forum.unity3d.com/threads/rigidbody-getting-stuck-on-tiled-wall.220861/
For 3D games I've always used a sphere or capsule collider on my character, and I don't encounter any problems with catching on the edges of the box colliders that make up the environment.
Whether there's any other approach that would help I'm not sure.
Answer by Bunny83 · Jun 26, 2016 at 10:01 PM
Your question is a bit confusing. Using ghost vertices is a way to prevent unwanted collision response. Unity actually uses Box2d as 2d physics engine. However it's integrated into Unity and you can't use all features as if you would use Box2d directly. Box2d is written in C++ (just like the Unity core). So there's no way to directly use it from Unity's scripting environment (which is implemented with Mono). Inside Untiy you can only use what the Unity API provides.
So you can't implement ghost vertices in a Unity EdgeCollider2d since it can only represent a continous edge / series of points. It's not possible to specify additional vertices which are not used as edge but are taken into account for calculating the collision response.
Your only option is to "bevel" the corners of your colliders. So where two colliders meet each other you would add another 45° edge which might overlap with the other collider so the character can't hit a vertical edge which is the reason why an object get stuck..
I'd be happy to deal with edge colliders entirely as I understand the issue (lack of knowledge of a selection of such adjacent colliders as a single entity), but I wish Unity's 2D physics system would do one of the following:
Provide an easy filtering/sorting mode for collisions (even controlled by a rect around a target, like the player) a bit like some games prioritising horizontal collisions over vertical. Prioritising Y-axis collisions deep within the collision engine is fine until you want to support a rotating world or to switch gravity direction to 1,0 or -1, 0.
Allow us to push new geometry into an edge collider, so we can temporarily join a moving platform to a connecting, parallel area of ground - even if this is computationally expensive. $$anonymous$$y use case is a simple (i.e. small-scale) platformer that occasionally involves an interesting physics shape, like a large windmill (making it difficult to use a simpler collision engine).
The point about moving platforms is my main issue, though.