Hi there! I have been having a problem with my placement system’s rotate function. It should work, and I do not see any errors. However, it is behaving weirdly. This is how it works:
When the mouse moves, I update the positions of the mouse. This part works fine. I am using a grid based system.
if mouse.Target.Parent == game.Workspace.Garden then local object = game.Workspace.Placeholders:FindFirstChildWhichIsA("Model") posx = mouse.Target.Position.X posy = mouse.Target.Position.Y posz = mouse.Target.Position.Z local finalrotate = Getfinalcframe() object:PivotTo(object.Primary.CFrame:Lerp(finalrotate, 0.8)) end
This is the getfinalcframe function:
function Getfinalcframe() return (CFrame.new(posx, posy, posz) * CFrame.Angles(0, math.rad(rotation), 0)) end
This handles rotation:
if posx ~= 0 or posy ~= 0 or posz ~= 0 then rotation = rotation + 90 if rotation == 360 then rotation = 0 end print(rotation) local finalrotate = Getfinalcframe() print(finalrotate) local object = game.Workspace.Placeholders:FindFirstChildWhichIsA("Model") object:PivotTo(object.Primary.CFrame:Lerp(finalrotate, 0.8)) end
Edit: I worked something out. It does appear to be working, just not the first couple of times. So I press it a bunch of times, and in small increments it gets to about 45 degrees, then starts rotating at a 90 degrees interval.
The system works like it should, it adds the rotation, and turns back to zero. But for some reason, when rotate, I get this: https://gyazo.com/f247c8ec8f384ff5fd2737300269e67e
The video is of me pressing rotate a bunch of times, hence the small movements at the end. I am not sure why each time i press it, it rotates less.
I am not sure if there is something wrong with my maths or I am using something wrong. It in theory should work. The grid works, however. (When I move my mouse, it will update the position, just not the rotation.)
Can collide is off, the model is welded properly, and it is anchored.
Any help would be greatly appriciated!