Rotating a part in the "correct" direction

Hi y’all! I’m trying to make a part move and rotate through the specified waypoints while the front surface faces them but I ran into a problem: sometimes it makes a weird rotation and instead of going to right (like an obvious choice) it rotates to left and makes something like almost a 270° or 360° rotation.

I have 2 tweens, one for position and one for orientation. I’m not using CFrame (but I tried with it) to tween both because I want the orientation tween faster than position.

Here’s an example of what I’m trying to achieve:

And here’s how I’m trying to do it (tweening orientation):

local CFrame = CFrame.lookAt(part.Position, waypoint.Position)
local X, Y, Z = CFrame:ToOrientation()

local Tween = TweenService:Create(part, TweenInfo(0.25), {Orientation = Vector3.new(math.deg(X), math.deg(Y), math.deg(Z))})
Tween:Play()

Any help appreciated!

TweenService:Create(part, TweenInfo(0.25), {Position = Vector3.new(x, y, z)}):Play()
Tweening the part to the next waypoint

use math.rad not math.deg‎‎‎‎‎‎‎‎ㅤ‎‎‎‎‎‎‎‎ㅤ‎‎‎‎‎‎‎‎ㅤ‎‎‎‎‎‎‎‎ㅤ‎‎‎‎‎‎‎‎ㅤ‎‎‎‎‎‎‎‎ㅤ‎‎‎‎‎‎‎‎ㅤ

or dont use anything only out x,y and z

I tried using math.rad and also leaving them like that but the part doesn’t even rotate. I saw using math.deg converts it to degrees (because looks like CFrame returns it on radians, not sure about it) and fixes it but my problem is about how the part rotates to the left or right to face the new waypoint (because sometimes it rotates to right side doing a whole turn and the waypoint was at its left side)

I already have a tween for position and also tried with this but it’s not fixing my issue

Somehow, using task.spawn and CFrame.new instead of CFrame.lookAt fixed it. I don’t know I didn’t think about it but it works perfectly now

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.