One of the most common things you do in video games is detecting a surface of an object. You do it when you want to play a footstep sound and particle, when you want to show a bullet decal on a wall or when you want to know if you have hit a soft body or a hard metal.
Since it’s so commonly used it should be written in a way that is easy and efficient to utilize. For our game The Lightbringer we have created a simple yet effective system from a few parts.
First we have a surface type:
This is basically just data. We then create scriptables for each surface type.
Then we have a Surface script that can be attached to any object on the scene:
And the most important part, where all the magic happens, the surface manager:
Here we keep a lookup of all the surface objects. Upon starting the game, every surface registers in this lookup.
When we want to check what surface type any object has we can use GetSurfaceType method. A simple example:
And that’s all there is to it. It’s pretty straightforward, nothing revolutionary, but then again I saw so many projects which lacked a system like this, that I thought I’d share.
If you want to check out our work: https://linktr.ee/rock_square_thunder