Proper way of doing hit velocity?

I want to make something seemingly simple by having a crash sound play when the player bumps into anything above a certain speed.

I managed to set up some nodes that succesfully plays the sound when the player smashes into a wall, and doesn’t if it gently taps it.

However, the problem I’m still facing is if the player slides off or scrapes by an object, it also starts playing the crashing sound a trillion times as soon as the sliding speed goes over the limit, since the engine doesn’t differentiate a hard frontal hit from simply touching.

I’m looking for a way to only have the crash sound play if the player hits the object within a certain angle perpendicular to the surface that it is hitting. So far the documentation has been left to be desired, and I can neither find any info on this elsewhere.

I’d guess that the Hit Normal from the Event Hit node could be involved with this, but I can’t seem to make too much sense of it yet, if it’s even related at all.

Does anyone have any idea?

1 Like

Aye. You’re looking for dot product whose value goes from -1 <> 1 and, if needed, can be treated as an angle in degrees or radians.

Try this:

It would only print if we hit a wall at 45 deg or so which is dot .7 or thereabouts. In short:

  • compare the normal of the hit surface with the direction the character is facing
  • stuff behind us is below 0, ahead of you is above 0, and all the values in between

To visualise what dot product is doing:

1 Like

Thank you very much! That was exactly what I needed. I was not familiar with the Dot product node yet.

Now if I slam into anything it correctly plays the crashing sound. Yet if I slide over an object at speed it keeps silent unless I hit another obstacle along the way.

You’ve saved me a great headache, thank you.

1 Like