 # Arrow Projectile Rotation Not Working

You can write your topic however you want, but you need to answer these questions:

1. What do you want to achieve? Keep it simple and clear!

Workout The Rotation Of my Arrow Projectile

1. What is the issue? Include screenshots / videos if possible!

The speed of the projectile is not really a issue I haven’t worked on that yet, I’ve been trying to fix the rotation, this how it looks like without rotation since, I scraped the atan2 idea since its only gave me 1 value…
robloxapp-20220622-2343080.wmv (3.8 MB)

1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have no idea how to do this, I tried using Atan2 but this only have me the X rotation, and the arrow still landed sidewards into the ground.
I also Tried converting the vectors into a cframe and use The :ToObjectSpace, however this was just unsuccessful.

This is the script I use to calculate the position of the arrow, can someone help me to add a calculation that I could return back through that function, thank you ``````function lerp(a, b, c)
return a + (b - a) * c
end

local Bowmodule = {}

function Bowmodule.BezierCurve(t, p0, p1, p2)

local l1 = lerp(p0, p1, t)
local l2 = lerp(p1, p2, t)
local quad = lerp(l1, l2, t)

local X = math.abs(l2.X - l1.X)
local Y = math.abs(l2.Y - l1.Y)

--local cframeRotationalDifference = CFrame.new(l1):ToObjectSpace(CFrame.new(l2))
--local newCFrame = CFrame.new(l1)*cframeRotationalDifference

end

return Bowmodule
``````

And here is how I call it

``````replicatedStorage.Events.RangeEvents.Fire:FireServer(tool,Fire.TimePosition/Fire.Length,tool.Handle.Position,mouse.Hit.Position)
``````

Fire is the animationTrack of drawing the bow and Firing.

bump bump bump bump bump bump bump bump bump bump bump bump bump bump bump bump bump bump bump bump bump bump

I’ve been playing around with the values and this is what I managed to get to… It still give me bad orientation but its better than it was… someone help? Here is the script…

robloxapp-20220623-1323393.wmv (8.7 MB)

``````local rs = game:GetService("RunService")
function lerp(a, b, c)
return a + (b - a) * c
end

function Angle(vectorA, vectorB)
return math.acos(vectorA:Dot(vectorB) / (vectorA.Magnitude * vectorB.Magnitude))
end

local Bowmodule = {}

function Bowmodule.BezierCurve(t, p0, p1, p2)

local l1 = lerp(p0, p1, t)
local l2 = lerp(p1, p2, t)
local quad = lerp(l1, l2, t)

local X = math.abs(l2.X - l1.X)
local Y = math.abs(l2.Y - l1.Y)

--local X2 = Angle(l1,l2)
--local Z2 = Angle(l2,l1)

local X2 = math.abs(l2.X - l1.X)
local Y2 = math.abs(l2.Y - l1.Y)

local X3 = math.abs(p2.X - quad.X)
local Y3 = math.abs(p2.Y - quad.Y)

local Theta = math.atan2(Y3, X3)

local Theta2 = math.atan2(Y2, X2)

local Orientation = Vector3.new(math.deg(Theta2)-90,0,math.deg(Theta)-90)--X2,--Y2,0)

--print(Orientation)

--rs.Heartbeat:Wait()

end

return Bowmodule

``````

I improved the mechanics once again, however it still doesn’t look realistic. The arrow now spins around in the right direction, but in the last second in spins around to the other direction, if not that it would be perfect… I changed it so I just create a cFrame and set the direction of it and set it onto the part instead of setting the position and then playing with rotation. anyone helpppp??? bumpp //edit Also it starts off in wrong position I have trouble to set it normal to the bow…

robloxapp-20220623-1713173.wmv (4.5 MB)

``````local rs = game:GetService("RunService")
function lerp(a, b, c)
return a + (b - a) * c
end

function lookAt(target, eye)
local forwardVector = (eye*Vector3.new(1,4,1) - target).Unit
local upVector = Vector3.new(0, -1, 0)
-- You have to remember the right hand rule or google search to get this right
local rightVector = forwardVector:Cross(upVector)
local upVector2 = rightVector:Cross(forwardVector)
return CFrame.fromMatrix(eye, rightVector, upVector2)
end

local Bowmodule = {}

function Bowmodule.BezierCurve(t, p0, p1, p2)

local l1 = lerp(p0, p1, t)
local l2 = lerp(p1, p2, t)
local quad = lerp(l1, l2, t)

return cF

end

return Bowmodule

--local X = math.abs(p2.X - quad.X)
--local Y = math.abs(p2.Y - quad.Y)

--local Theta = math.atan2(Y, X)

--print(Theta)

--local X2 = Angle(l1,l2)
--local Z2 = Angle(l2,l1)
--[[
local X2 = math.abs(l2.X - l1.X)
local Y2 = math.abs(l2.Y - l1.Y)

local X3 = math.abs(p2.X - quad.X)
local Y3 = math.abs(p2.Y - quad.Y)

local Theta2 = math.atan2(Y2, X2)

local Orientation = Vector3.new(math.deg(Theta2)-90,0,math.deg(Theta)-90)--X2,--Y2,0)

--print(Orientation)

]]--

--rs.Heartbeat:Wait()
``````