Calculating angle of hit from an "weapon" in VR

Okay. So i’ve been racking my brain with this for a while but cannot seem to fathom how to do it with blueprints.

Basically in my project i have a situation where an target is supposed to be stunned. This mean that the stun weapon needs to be closed enough to the target and not have a big angle (something like 10 is okay, 45 isn’t)
My problem is that i cannot wrap my head around how to do it. It must be something stupidly obvious but still. I know the formula for the calculation but cannot transfer it to the blueprints.

Any pointers or help would be greatly appreciated! And anyway have a great day.


Could you maybe elaborate a bit as I have some issues understanding what you mean by “the stun weapon needs to be closed enough to the target” is it the Enemy targets weapon or the player’s weapon that hit the target? In what context is this happening.

When I have a hard time understanding the problem I start with Paint, and if it still is hard I go for my programmer ducks/cardboard dogs.

dot product is cosinus of angle. If it does not matter if angle is positive or negative then dot product between impact vector and normal vector to hit surface is all you need.
If you want also left\right information you need to make another dot product with right vector of impact and normal (to get if direction is positive or negative). But that is used for player controllers mostly.

this little critter is what you need:

Ps. make sure you NORMALIZE both vectors that you put into dot.

You might find this article on Dot product interesting for your application: Practical use of Vector Math in Games - Math and Physics - Tutorials -

Try something like this

Camera - is camera forward vector.

Ahh sorry about that. To try and clarify is that there are animals you need to stun with a weapon (this is educational so mimicks what you would do in real life) and in real life you need to get the stun gun pressed against the animals head straight and without an angle on or you risk hurting the animal instead of blacking it out. (i hope the the picture at least somewhat helps to explain it.)

I need to calculate the angle of hit to see if it was done properly. Sorry for being so unclear with this ^^’

That is somewhere along what i’ve been thinking i’d say, just have had a hard time putting it into code. Needed as much validation to my thinking as actual help. Will have a look at that, thank you!

Will most certainly give it a good read, thank you for your help!

Will give it a shot and see what i can make of it. Thank you for your assistance!

Yeah, it sounds like something a dot product could help you out with, just make sure that you calculate from the right location. :slight_smile:

Depending on the design and setup of the StunGun and if you always need to press it towards the animal’s head you might be better off with colliders on each side, where all of them need to “collide” for it to succeed.

Good Luck!