informa
/
Programming
Featured Blog

Fast surface recognition system in Unity3D

How to efficiently and easily detect a surface for audio, particles, or gameplay.

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

Janusz

Latest Jobs

Sucker Punch Productions

Bellevue, Washington
08.27.21
Combat Designer

Xbox Graphics

Redmond, Washington
08.27.21
Senior Software Engineer: GPU Compilers

Insomniac Games

Burbank, California
08.27.21
Systems Designer

Deep Silver Volition

Champaign, Illinois
08.27.21
Senior Environment Artist
More Jobs   

CONNECT WITH US

Register for a
Subscribe to
Follow us

Game Developer Account

Game Developer Newsletter

@gamedevdotcom

Register for a

Game Developer Account

Gain full access to resources (events, white paper, webinars, reports, etc)
Single sign-on to all Informa products

Register
Subscribe to

Game Developer Newsletter

Get daily Game Developer top stories every morning straight into your inbox

Subscribe
Follow us

@gamedevdotcom

Follow us @gamedevdotcom to stay up-to-date with the latest news & insider information about events & more