# Dot product not dot producting

I’ve attached images of my current dot product code and the lines I’m trying to work out the angle between. I keep trying to remake this or make it work based on tutorials but somehow I just keep making it worse.

I’m trying to work out if the player is over 40 degrees to the right or left of the turret, and I have to use dot product to do this because it’s for an assessment, but the math just isn’t mathing.

Am I doing something wrong???

Edit, made a few adjustments to the code, it’s still not working but I think I’m 20% closer??

Except now it thinks the right angle from the character is 0 degrees and I have no idea how I can combat this in code aa

the math just isn’t mathing

• no need to normalise `forward`, it’s already normalised
• the 2nd vector is incorrect:

This is direction to the player from world origin 0,0,0 and does not account for where the turret is. Instead of player location, do `Unit Direction` from `Turret World Location` to `Player World Location` and feed that into the `dot` node:

No need to normalise Unit Direction - already normalised as well. Your pic seemed OK at a (very quick) glance, though! In case the above does not produce what it should:

Do double check how this is rotated.

Sorry deleted the last one since I noticed you were still updating it and didn’t want to get confused in the process-

I have this now but I’m still not sure if it’s 100% accurate?? Idk too much for my brain too late at night

Also is there a specific way I should check if it’s in the target range of 40 degrees? I get the feeling I may not be doing that right either

I have this now but I’m still not sure if it’s 100% accurate?

You may need to elaborate on that.

You could try:

Shaves some nodes off the script.

Not exactly sure what the ideal end result is but you could try this slightly more versatile approach:

Idea end result is kind of like an angle of attack where the turret can spot the player. If they’re in between 40 degrees left to right in front of it, it should be able to spot them.

Just tried the in range you suggested and it worths perfectly so thanks, you’re a sanity saver- I can sleep in peace tonight

• dot returns -1 : 1
• 0-1 when vectors do align
• it cannot produce -140 in this very case

Try:

But you may need transforms (as in the other thread) - depending on how relative attachments are made.

Yep that worked, thanks again!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.