I’m making a script that turns the mouse delta into object rotation, but a problem arises. It rotates the object in the local axes of rotation because of this, it is not convenient to do so. How could I rotate an object around global axes? Like in second screenshot.
I assume you’re writing a script to do this, if you want to do it in world space, multiply the rotation times the current cframe, not the other way around.
Rotation around Y-axis is good but around X-axis is weird
UserInputService.InputChanged:Connect(function(input, gameProcessed)
--if gameProcessed then return end
if input.UserInputType == Enum.UserInputType.MouseMovement and RotationMode then
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
rotateVector += Vector2.new(input.Delta.X, input.Delta.Y)
end
end)
local function UpdateRotatePart(rotateVector)
if not RotationPart or not LocalVisualPart then return end
local x, y, z = Camera.CFrame:ToOrientation() -- This need for part look at player
RotationPart.CFrame = CFrame.new(LocalVisualPart.Position)
RotationPart.CFrame *= CFrame.fromOrientation(math.rad(rotateVector.Y), math.rad(rotateVector.X) + y, z)
return
end