informa
/
1 MIN READ
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

Treyarch

Playa Vista, Los Angeles, CA, USA
9.12.23
Senior Level Designer (Zombies)

PlayStation Studios Creative Arts

Petaling Jaya, Selangor, Malaysia
9.14.23
Lead Concept Artist

Digital Extremes

Remote
9.27.23
Lead AI Programmer
More Jobs   

CONNECT WITH US

Explore the
Advertise with
Follow us

Game Developer Job Board

Game Developer

@gamedevdotcom

Explore the

Game Developer Job Board

Browse open positions across the game industry or recruit new talent for your studio

Browse
Advertise with

Game Developer

Engage game professionals and drive sales using an array of Game Developer media solutions to meet your objectives.

Learn More
Follow us

@gamedevdotcom

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