23 September 2015

Concave triggers in Unity 5

We're currently in the progress of converting our game to Unity5. Not as easy as I had hoped it would be, but that's for another post :)

One of the things that changed in Unity5 is that concave triggers are not possible anymore. They used to be, but they triggered enter/exit events every time a collider passed through the surface of the trigger. Now you just get an error that you can't have concave triggers.

Too bad for us, because we used a lot of them via my Area Trigger system. The code in that post is obsolete in Unity 5 (as are many of my other Unity-related posts). So I've updated the code on bitbucket.

To recap: the idea of the area trigger concept is that it exists of a height and a 2d polygon, that can be concave. This defines a concave volume. We can then add a mesh trigger and flag it as convex. We now receive events from the convex volume, we check these against the concave volume and if the collider is in the concave volume we pass an area trigger event.

The only downside now is that we check whether the position of the collider is in the area trigger instead of the whole volume (which would be far more difficult and obviously the reason why even PhysX doesn't do it). For our purposes however this is enough; we use these area triggers to establish whether the player or an npc walks into a zone (or area, hence the name) in the scene.

A colleague of mine added a cool feature that was requested by our artists: you can now also use the system to create area colliders. With it, you can quickly generate simple mesh colliders as blockers in Unity, instead of having to create them in a modelling tool, where this doesn't make much sense. (I hate FBX files where visuals and physics are mixed).

The shading system also changed a bit in Unity 5, we can't create shaders from a string anymore for example, so I changed the visualization of the triggers as well.


No comments: