Determining impact angle of a projectile

Anyone know of a way I can determine the impact angle of a projectile on another brick?

1 Like

Given the initial velocity, initial position, collision position, and gravity you can do:
(This assumes that there is no air resistance or any force but gravity acting on the projectile)

Also the main assumption this makes is you know the exact collision point, if you don’t know this then rip xd
I will try figuring out how to do plane with quadratic intersection (it would work only for basic baseparts not special meshes and stuff) but if you figure it out before me please share :stuck_out_tongue_winking_eye:

Anyways you can do this XD:

local g = workspace.Gravity -- gravity
local vel = Vector3.new(1,5,0) -- initial velocity (magnitude = speed)
local origin = Vector3.new(0,0,0) -- launch position
local xc = 0.56 -- x coordinate where collision occured (collision.X)
local zc = 0 -- z coordinate where collision occured (collosion.Z)
-- y coordinate where collision occured is not necessary

local atan = math.atan
local tan = math.tan
local cos = math.cos
local deg = math.deg(1)

xc = xc - origin.X
zc = zc - origin.Z

local x = (xc*xc + zc*zc)^0.5 -- horizontal distance traveled
local theta = atan(vel.Y/(vel.X*vel.X + vel.Z*vel.Z)^0.5) -- launch angle
local v = vel.Magnitude -- initial speed

-- take the derivative of the trajectory equation: x*tan(theta) - g*x*x/(2*v*v*cos(theta)^2) to get the slope at xc
local slope = tan(theta) - g*x/(cos(theta)^2*v*v)
local angle = deg*atan(-slope)

print(angle)

Edit
This would be plane intersection to find xc if you don’t know the precise collision point but still know the part’s cframe and size:

This will just find the collision points between a plane (treated as a straight line in 2d space) and the trajectory

You will need to discard the collision points outside of the part’s bounds.
Also you can find the part’s bounds and slope by doing part.CFrame * CFrame.new(part.Size.X/2,0,0) + and - for the X plane and the same for all the others plus the appropriate y offset and z offset

it gets really messy though so I hope you have the collision point LOL

local function planeIntersection(v,theta,m,b)
	-- assumes this is in local space of the trajectory (origin = trajectory launch point)
	
	local a = -g/(2*v*v*cos(theta)^2)
	local b2 = tan(theta)
	-- c = 0
	
	local d = (b2 - m)*(b2 - m) + 4*a*b
	if d == 0 then
		-- one intersection
		return (m-b2)/(2*a)
	elseif d > 0 then
		-- two intersections
		return (m-b2 + d)/(2*a),(m-b2 - d)/(2*a)
	end
end

If you know the surface normal and projectile’s velocity, it’s

aoi = pi/2 - acos(-dot(vel, norm))
4 Likes