So I want to know what the best rotation would be for a position based lerp. The problem is I can’t figure out what the best one is. I have tried to do tween but the alignment on the position just gets all messed up. I have also tried to do align position and align orientation but those seemed like the object was falling behind unless if someone could explain how to use them better. These are the arrows and not enemies or units.
Code:
local ServerStorage = game:GetService("ServerStorage")
local PhysicsService = game:GetService("PhysicsService")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local events = ReplicatedStorage:WaitForChild("Events")
local arrow = {}
function arrow.LerpTo(newArrow, target)
local alpha = 0
local startCFrame = newArrow.Position
local loop
local loopBool = false
local distance = (newArrow.Position - target.Position).Magnitude
loopBool = true
loop = RunService.Heartbeat:Connect(function(deltaTime)
local speed = 40
local relativeSpeed = distance / speed
local goalCFrame = startCFrame:Lerp(target.Position, alpha)
newArrow.Position = goalCFrame
alpha += deltaTime / relativeSpeed
if alpha >= 1 then
loop:Disconnect()
loopBool = false
end
end)
repeat task.wait()
until loopBool == false
end
function arrow.Move(newArrow, pathNum, map)
local waypoints = map:FindFirstChild("Waypoints"..pathNum)
local newPos
for waypoint=2, #waypoints:GetChildren() do
newPos = waypoints[waypoint]
arrow.LerpTo(newArrow, newPos)
end
newArrow:Destroy()
end