How to get angle of hit from ray

Let’s say tank shoots another tank, you get an angle and it’s 100°. Most likely the tank won’t penetrate the armor. How could I get angle from a raycast shot?

local ray = Ray.new(startVector, (endVector - startVector).unit * Configuration.FireRange.Value)
local hit, position, normal = workspace:FindPartOnRay(ray, Tank, false, true)
local distance = (position - startVector).magnitude
6 Likes

I don’t think getting the angle is possible (in an easy way)… I know it’s possible to get the side hit by normalId.

If your interested on working really hard to figure it out, I recommend associating surface normal vectors with degree angles on the X and Z axis’.

This is really easy, you just need to take the math.acos of the dot product of the two direction vectors, so that would be math.acos(ray.Direction:Dot(normal))

1 Like

it keeps returning image

Oh right, you need to make sure the direction vectors have been normalized, so it should actually be math.acos(ray.Direction.Unit:Dot(normal.Unit))

6 Likes


how is this 1.8289651343515 lol? do I am doing something wrong?

this looks more like 40-60°

1 Like

The result will be in radians, so that looks ok to me.

how I convert it to degrees?

sorry If I sound dumb, but I never dealt with this stuff before.

math.deg(result) you can find, all the math functions here

3 Likes

Hey can you tell me what “normal” here is? How do I find it?

So this method is nearly 8 months old, and has actually been deprecated. You should be using the new raycasting function, in which you will receive an instance from a raycast. You would get the normal from the returned raycast result instance if the raycast returned anything.

1 Like