Trajectory Launch Angle

Im trying to calculate and get information to tell me what angle I need to reach the desired distance.

This works almost flawlessly, I took it from another article “Arc Based projectiles” it works when the distance is about 400+ studs but any closer and the angle is too steep. I had it working before it was perfect then something happened and honestly I have no idea what changed.

    local function QuadraticEq(a, b, c)
	local sq = math.sqrt(b^2 - 4*a*c)
	
	return {(-b + sq)/(2*a), (-b - sq)/(2*a)}
end

local g = workspace.Gravity		-- gravity
local x = 180					-- distance to target
local y = -30 					-- y displacement (amount of drop)
local s = 509 					-- mag of initial vel (studs/sec)

local a = (-g*0.5*x^2)/(s^2)
local b = x
local c = a - y

local result = QuadraticEq(a,b,c)

-- one of these is the angle for firing right at the target and the other is for lob
print("DEGREE ANGLE1", math.deg(math.atan(result[1])))
print("DEGREE ANGLE2", math.deg(math.atan(result[2])))

I don’t need bullet drop, im just looking for the angle I need that will have the projectile fly to the designated distance, The listed code gives -5.589 as the designated angle it should be more like 0.1

I probably butchered the explanation but any guidance would be very useful i’m fairly new to the Quadratics and boy is it a headache

1 Like