Need help with relative CFrame rotation

What l am trying to achieve is similar to Lumber Tycoon 2’s rotation system.

Right now, I am moving an object with the same rotation and position relative to the camera Iike so:

What I would like to be able to do, is rotate the object, however it is oriented, up down left and right relative to the camera like so:

Anyone know what math l can use to achieve this?

1 Like

I think you should make some variables like this:
and then use UserInputService to check.

local UIS = game:GetService("UserInputService")
local runSvc = game:GetService("RunService")

local holdingShift = false
local breakLoop = false

UIS.InputBegan:Connect(function(input, event)
	if event then return end
	if input.KeyCode == Enum.KeyCode.LeftShift then
		breakLoop = false
		UIS.InputBegan:Connect(function(input, event)
			if event then return end
			if input.KeyCode == Enum.KeyCode.A then
				while wait(0.1) do
					if breakLoop then break end
					yourPart.Orientation = yourPart.Orientation + Vector3.new(1,0,0) -- I'm not so good at direction stuff so it might be wrong 
				end
			elseif input.KeyCode == Enum.KeyCode.A then
				while wait(0.1) do
					if breakLoop then break end
					yourPart.Orientation = yourPart.Orientation + Vector3.new(-1,0,0) -- I'm not so good at direction stuff so it might be wrong 
				end
			elseif input.KeyCode == Enum.KeyCode.A then
				while wait(0.1) do
					if breakLoop then break end
					yourPart.Orientation = yourPart.Orientation + Vector3.new(0,1,0) -- I'm not so good at direction stuff so it might be wrong 
				end
			elseif input.KeyCode == Enum.KeyCode.A then
				while wait(0.1) do
					if breakLoop then break end
					yourPart.Orientation = yourPart.Orientation + Vector3.new(0,-1,0) -- I'm not so good at direction stuff so it might be wrong 
				end			
			end
		end)
	end
end)

UIS.InputEnded:Connect(function(input, event)
	if event then return end
	if input.KeyCode == Enum.KeyCode.LeftShift then
		breakLoop = true
	end
end)	
2 Likes

I appreciate the help, but I already have UlS set up. And orientation is not what l am looking for.

1 Like

Set the skulls cframe to CFrame.new(SkullPosition, (LocalCamera.CFrame * CFrame.new(0,0,-100)).p) This will make the part follow the center of your screen.

1 Like

Thanks Spathi, but l’m trying to rotate the skull relative to the camera with WASD. l already have the picking up part down.

1 Like

Oh I’m so sorry. I misread completely. I’ll try and help again lol.

1 Like

I found this post that has just about what I need, but I cannot implement it for the life of me. I always get close.

--[[CurrentObjectOffset is the position and rotation relative
 to the camera when the object is first picked up. 
]]

function UpdateBodyMovers()
	if LiftingObject then
		if (CurrentObject.Position - Root.Position).Magnitude > GrabRadius then
			LiftingObject = false	
			DropObject()
		else
			CurrentObject.Mover.Position = (Camera.CFrame * CurrentObjectOffset.Position)
			CurrentObject.Gyro.CFrame = Camera.CFrame * CurrentObjectOffset - CurrentObjectOffset.Position
			
			if ShiftDown and CurrentObject then
				if not W and not S or not A and not D then
					if W then
				
					end
					if S then
						
					end
					if D then
						
					end
					if A then
					
					end
				end
			end
		end
	end
end

This is the code I currently have. The problem I was having with implementing the code from the post linked above:

I was able to make the object rotate relative to the camera when pressing W, but when I would move it around, the object’s rotation would be relative to the world space, and not the camera anymore like the video I initially posted.

I need the object to rotate towards the camera, and when it is moved around, have its rotation be relative to the camera as well.

Someone please ATTEMPT to help. I am desperate. If you have more questions I will try to answer them.