How do I make this script tween both orientation and position (using :lerp() is not an option due to it causing lag)
local TweenService = game:GetService("TweenService")
local Speed = 10 -- How many studs you want to go per second
local function calcDist(point1, point2)
return (point1 - point2).magnitude
end
local wp = 1
while game.Workspace.Waypoints:FindFirstChild(tostring(wp)) do
local Pos1 = script.Parent.CFrame
local Pos2 = CFrame.new(game.Workspace.Waypoints[tostring(wp)].Position)
local Distance = calcDist(Pos1.Position, Pos2.Position)
print(Distance)
local Time = Distance/Speed
print(Time)
local TweenInf = TweenInfo.new(Time, Enum.EasingStyle.Linear)
local TweenGoal = {CFrame = Pos2}
TweenService:Create(script.Parent, TweenInf, TweenGoal):Play()
wait(Time) -- Wait for the tween to finish before moving to the next waypoint
wp = wp + 1
end
local TweenGoal = {
CFrame = Pos2 ,
Orientation = Pos2 - Pos1.Position -- Calculate the orientation based on the difference between Pos2 and Pos1
}
TweenService:Create(script.Parent, TweenInf, TweenGoal):Play()
local TweenService = game:GetService("TweenService")
local Speed = 10 -- How many studs you want to go per second
local function calcDist(point1, point2)
return (point1 - point2).magnitude
end
local function createTween(obj, property, goal, time, style)
local tweenInfo = TweenInfo.new(time, style)
local tweenGoal = {}
tweenGoal[property] = goal
return TweenService:Create(obj, tweenInfo, tweenGoal)
end
local wp = 1
while game.Workspace.Waypoints:FindFirstChild(tostring(wp)) do
local startPos = script.Parent.CFrame
local endPos = CFrame.new(game.Workspace.Waypoints[tostring(wp)].Position)
local distance = calcDist(startPos.Position, endPos.Position)
print(distance)
local moveTime = distance / Speed
print(moveTime)
local rotationTween = createTween(script.Parent, "Rotation", endPos - startPos, moveTime, Enum.EasingStyle.Linear)
local positionTween = createTween(script.Parent, "Position", endPos.Position, moveTime, Enum.EasingStyle.Linear)
rotationTween:Play()
positionTween:Play()
wait(moveTime) -- Wait for the tweens to finish before moving to the next waypoint
wp = wp + 1
end
welp I give up and ur right CFrame.new() value uses the position and not orientation?
I’ll try to help you but at the same time GoodLuck On Finding an aNSWer
Pos1 - Pos2.Position will give you another cframe because Pos1 is a cframe and cframe - vector3 is a cframe. You should use parantheses. Idk why you are taking difference of positions to rotate an object tho