How can I affect a material based on collision?

Hello,

I was wondering how I could go about adding dynamic functionality to a shader. For instance, let’s say I wanted a force field shader that would create a flash and ripple based on a collision location? So I could throw the force field shader on, say, a sphere and then shoot the default weapon at it and display a ripple/flash everywhere the projectiles hit.

Can anyone point me in the right direction?

Thanks!

Hello camelotvfx,

In order to achieve the effect you would like, you will first need to have your object (projectile) generate hit events. When this object registers a hit on whatever surface it collides with (your force field), you can spawn a particle system to sort of ‘flash’ in front of the user. You can then get the nearest vertex on your surface in which the material is applied and have a sort of ‘wave distortion’ move across the surface.

This would be the more simplified and quicker solution to your question. It will effectively fake the effect you are going for, but will not be perfectly accurate. Currently there is no known way to get the exact location of collision between your two objects and translate that number to a material effect through blueprints. The more difficult and more math intensive way would be to program this into code, and use vector math to get your exact collision and apply a material effect that way.

Here is some really helpful documentation on collision and how the engine handles certain collision types.

Collision Documentation

Here is some more information on using a physical material for collision as well.

Physical Material Documentation

You also might be able to find some more information on the Unreal Engine Forums because there are a lot of great users on there doing some really cool and unique work. They are experienced and are generally very willing to share their information and tips on how to go about designing certain aspects of their games.

I hope this gets you on the right path. You might feel a bit overwhelmed at first because what you are trying to do is not a simple task. I would suggest going step by step of each process and attempt to understand the question ‘Why?’ to each one. If you are able to answer the question of why, then you will be able to set up things more freely and with greater control. This will ultimately give you the exact outcome you are looking for, but just be prepared to learn!

Cheers,