I want to make my enemy (a 1x1x1 cube for the server and render in client) follow the waypoints. when it needs to make a right turn, it should just turn 90 degree clockwise right, but it just turn left 270 degree. how to fix it? the waypoint is facing the right direction. https://gyazo.com/b65c4fa18c507369e6ebcf2bac2fd9be
function module.MoveEnemy(enemy, waypointFolder, enemyConfig)
for i = 1, #waypointFolder:GetChildren(), 1 do
local time = (waypointFolder[i].Position - enemy.Position).Magnitude / enemyConfig.Speed.Value
TweenService:Create(enemy, TweenInfo.new(time/8), {Orientation = waypointFolder[i].Orientation}):Play()
local walkTween = TweenService:Create(enemy, TweenInfo.new(time, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {
Position = Vector3.new(waypointFolder[i].Position.X, enemy.Position.Y, waypointFolder[i].Position.Z)
})
walkTween:Play()
walkTween.Completed:Wait()
end
enemy:Destroy()
end
so according to your code the orientation is waypointFolder[i].Orientation. means if you say it turns 270 degrees either the enemy instance’s front face isn’t correct or waypointFolder[i].Orientation wasn’t rotated correctly.
Yeah, it’s probably an issue with the orientation of the part because no other scripts are doing it. It can also be an issue with the tween itself because it may be trying to find the fastest way to rotate it, but that target rotation is not what you wanted.
Try this, make the waypoints named a certain direction
Forward, Left, Right
then tween the cube
function module.MoveEnemy(enemy, waypointFolder, enemyConfig)
for i = 1, #waypointFolder:GetChildren(), 1 do
local timetowalk = (waypointFolder[i].Position - enemy.Position).Magnitude / enemyConfig.Speed.Value
local orientation = {
Forward = CFrame.lookAt(enemy.Position, enemy.Orientation);
Left = CFrame.lookAt(enemy.Position, Vector3.new(enemy.Orientation.X, enemy.Orientation.Y, enemy.Orientation.Z)); --if x is left, then set X to enemy.Orientation.X - 90 (if not, do Z instead of X)
Right = CFrame.lookAt(enemy.Position, Vector3.new(enemy.Orientation.X, enemy.Orientation.Y, enemy.Orientation.Z)); --same here except it is +90
}
local TweenService = game:GetService("TweenService")
local orientationtween = TweenService:Create(enemy, TweenInfo.new(timetowalk/8, Enum.EasingStyle.Linear), {Orientation = orientation[waypointFolder[i].Name]})
local walktween = TweenService:Create(enemy, TweenInfo.new(timetowalk, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {Position = Vector3.new(waypointFolder[i].Position.X, enemy.Position.Y, waypointFolder[i].Position.Z)}
walktween:Play()
walktween.Completed:Connect(function()
orientationtween:Play()
wait()
end)
end
enemy:Destroy()
end
I don’t use Vector3 or position often so I don’t know if this would even work