Vector3 Rotation Starts Inverting After 90 Degree Rotation

I am making a place-able chair for my game Ba Hood. When you equip the chair as a tool, a preview of the chair appears locally at the position of your mouse. When holding R while in the preview mode, the preview rotates. By clicking, the client fires a remote event to the server, telling the server where to place the chair and in what rotation by checking the preview’s position and rotation, which causes another script to clone the chair to that position. If placing the chair while it is rotated in the preview, the chair spawns in that rotation. I use Vector3 to acquire this.

The problem is that after rotating the chair more than 90 degrees, instead of adding to the amount of degrees sending to the server, the client starts subtracting. For example, if I rotate the chair up to 90 degrees, the placement works fine, but after rotating the chair one more degree, the client sends the rotation of 89 degrees, and after rotating the chair two more degrees, the client sends the rotation of 88 degrees to the server. This continues down all the way to negative 90 degrees, when it starts going up again and works fine.

I have looked at the Roblox Documentation about vector3 and rotation where I have not found any clue to why this happens. I have also tried to learn about how CFrame rotation works, which I do not understand anything of.

I am using these lines of code to check and send the position and rotation:

local pos = mouse.Hit.p + Vector3.new(0, 2, 0)
local rot = script.Parent.Chair.Rotation.Y
script.Parent.AddBlock:FireServer(pos, rot)

Do you know why this happens? Is this how vector3 rotation works? Do you know of a solution? All help greatly appreciated!

P.S adding a video of what that happens. The output from the console is the amount of degrees the client tells the server to rotate the chair, printed from the client script.

1 Like

You should really look into CFrame. Try using CFrame.Angles, you are rotating beyond the parts current rotation so you don’t have to worry about it coming back or anything

Here’s a quick demo script using angles to rotate (just run in studio)

local newPart = Instance.new("Part",workspace)

newPart.Anchored = true
newPart.Position = Vector3.new(10,10,10)

while newPart do
	newPart.CFrame *= CFrame.Angles(0,0,0.1)
	task.wait()
end
1 Like

Tried it out, awesome, thanks! How would I get the Y rotation from this then?

You’d get the y rotation the same way as before

Well, that’s a problem, as it’s not rotating the block that goes wrong, but when I get the Y value.

Applying the rotation works fine.

Okay, so I found a workaround for this. The problem is still not solved, and I think it is a bug in Roblox. The way I solved this was that I, whenever the chair was rotated, set the rotation value to a NumberValue, where I saved it for later. When setting the NumberValue, the rotation was correct, as this happens when rotating the preview. I will mark this as the solution and report this to Roblox as a bug, even though I never solved the actual problem.

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