I am making a similar moving system like game called Noobs In Combat. The problem i’am facing currently is that when having to turn only 90 degrees it turns 270 degrees for some reason. Here is the video explaining how it looks like.
How did i do it? At first gotta get the old orientation and then new orientation by making the player face towards X of the tile i’ve clicked using CFrame.LookAt(). After that i set the part’s orientation back to old orientation. Then i tween it to make the target the new cframe. IT always has to turn 90 degrees or 180 degrees, but for my thing it sometimes rotates 270 degrees. So how could i fix it?
when I was making a tower defence game I had this problem this is how I fixed it. probably a better way.
local x,y,z = CFrame.new(node.Position, node_to_move_to.Position):ToOrientation()
x, y, z = deg(x), round(deg(y)), deg(z)
local poy = enemy.Orientation.Y
if poy < 0 and y == 180 then
y = -180
elseif poy == 180 and y == -90 then
y = 270
end
Are you tweening the rotation directly or the cframe?
If you are tweening the rotation it might be the case that the enemies rotate from 0 to 270 because they turn -90, and rotation loops (which tween service doesn’t account for).
Yes, but Orientation stores the rotation in a different format than CFrame, which causes weird issues like this. So you don’t really have any other way. Except if you were to create your own tween service, then it would be possible…
Another weird issue example: Gimbal lock
(the plane can no longer be rotated in 3 directions because two of the circles (pink and blue) are stuck in the same direction because of the angle of the green circle)
The pos with the desired rotation,
which you can combine like so:
position = ... -- vector3 position (without rotation)
rotation = ... -- cframe rotation (without position (0,0,0))
newPos = CFrame.new(position) * rotation -- order is important
Okay now The orientation thing is fixed but now its bugged and its teleporting when the first move is finished. Like its position becomes inbetween 2 tiles.
like before it moves i just rotate the thing toward where its supposed to go and then it comes back to his old position. After that i do the tween. I use CFrame.LookAt to know where to rotate