I'm using some stuff I've put together from various methods around the internet to make this work yet my bullets fly off in seemingly random directions. I've tried throwing negative signs in front of stuff and switching up the trig but to no avail. I've tried using the rotation of the player's arm because that accurately points to the user's mouse but that failed to give me any more accuracy.
I've tried to determine if the bullets follow a pattern like how I needed to invert the Y variable for my arm, but I cannot find a pattern here.
local x, y = objects.PlayerArm:GetPos()
local bullet = createBullet( x + objects.Player:GetWide(), y )
local mX, mY = gui.MouseX(), gui.MouseY()
local shootAngle = math.atan2((mY - y), (mX - x))
shootAngle = math.deg( math.Clamp(shootAngle, -90, 90) )
--shootAngle = objects.PlayerArm.Rotation
bullet.VelocityX = math.cos(shootAngle) * 5
bullet.VelocityY = math.sin(shootAngle) * 5
--bullet.Rotation = shootAngle
print("Angle", shootAngle, "Velocity X and Y", bullet.VelocityX, bullet.VelocityY)
Here is some of what was printed in console each time I shot a bullet.
Angle 47.920721521 Velocity X and Y -3.4948799788437 -3.5757256513158
Angle 24.928474135461 Velocity X and Y 4.8960495864893 -1.0142477244922
Angle 16.837472625676 Velocity X and Y -2.1355174970471 -4.5210137159497
Angle 10.684912400003 Velocity X and Y -1.5284445365972 -4.7606572338855
Angle -1.029154804306 Velocity X and Y 2.5777162320797 -4.2843178018061
Angle -11.63363399894 Velocity X and Y 2.978190104641 4.0162648942293
Angle -22.671343621981 Velocity X and Y -3.8872502993046 3.1447233758403