How to create Anti-Backward shooting precaution?

Hi Ya Dev Forum, Want a cookie?
No I am just kidding, sorry if this has already been posted but
I couldn’t find anything similar.

I want to prevent a Player from shooting backwards,
But I dont know how to make it…
Can somebody reference me a link or give me a basic idea of how to do this,
that would be much appreciated. :cookie:

2 Likes

See if the rays directions dot product to the players look vector is negative

Rays Directions Dot?
What is that essentially?
Which parameter is it?
Also thanks for the quick reply.

1 Like

https://developer.roblox.com/api-reference/datatype/Vector3

Do something like this:

local lookVector --the direction the humanoid or gun is facing
local shootVector -- the direction the bullet is going

local dotProduct = shootVector:Dot(lookVector)
if dotProduct < 0 then
	print("backwards")
end

The dot product function essentially sees how parallel two vectors are. You can view a visualizer here:

2 Likes