Cant get my character to rotate with mouse

hi, so basically im just skipping to the point, i have a custom camera script for a grabbing system, it works fine, however my character doesnt turn with the mouse. i tried using align orientation and body gyro, but those still didnt work.

heres the needed parts for the problem

script
RunService.Stepped:Connect(function()
	
	UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
	CameraData.CamPos = CameraData.CamPos + (CameraData.TargetCamPos - CameraData.CamPos) *0.28 
	CameraData.AngleX = CameraData.AngleX + (CameraData.TargetAngleX - CameraData.AngleX) *MouseData.Smooth
	local dist = CameraData.TargetAngleY - CameraData.AngleY 
	dist = math.abs(dist) > 180 and dist - (dist / math.abs(dist)) * 360 or dist 
	CameraData.AngleY = (CameraData.AngleY + dist *MouseData.Smooth) %360
	camera.CameraType = Enum.CameraType.Scriptable
	camera.CameraSubject = Player.Character.HumanoidRootPart
	camera.CFrame = CFrame.new()
		* CFrame.Angles(0,math.rad(CameraData.AngleY),0) 
		* CFrame.Angles(math.rad(CameraData.AngleX),0,0)
		+ Character.HumanoidRootPart.Position
		+ Vector3.new(0,1.5,0)



	Step = Step + 1 -- this part is about grabbing system, dont know if its needed or not
	if Step % 3 == 0 then
		if Grabbing then
			local BaseCFrame = camera:GetRenderCFrame()
			PosAtt.WorldPosition = BaseCFrame.Position + (BaseCFrame.LookVector.Unit*7)
			local RayCast = 
                   Ray.new(Character.HumanoidRootPart.Position,Vector3.new(0,-3,0))
			local Hit = workspace:FindPartOnRay(RayCast, Character)
			if CameraData.AngleX < -75 or Hit == Part then
				if Part and Align then
					Align:Destroy()
					Grabbing = false
				end
			end
		end
	end
end)

so yeah, what do i do?

1 Like

bumping :frowning: i still cant fix this

Could you show us a video? Why exactly are you locking the mouse to the center?

because the game should be in the first person

about the video,

Hmm I see.

You said you tried using BodyGyro. Could I see the script for that? I can think of three reasons why BodyGyro woudn’t work

  • The BodyGyro doesnt have enough force
  • The BodyGyro CFrame is wrong
  • There is an error

Maybe check for these things.

Or one of the parts is anchored…

before the .stepped, i used this code for it
local PosAtt = Instance.new("Attachment",workspace.Terrain) - posatt is needed for grabbing system
local BG = Instance.new("BodyGyro")

BG.Parent = Player.Character.HumanoidRootPart

and in the stepped function, i used this.
BG.D = 300
BG.P = 300000
BG.MaxTorque = Vector3.new(400000000, 0, 400000000)
BG.CFrame = PosAtt.CFrame

Not enough force… the Y axis is the rotation of the BodyGyro to orient the left and right rotation of the assembly

1 Like

i did all the forces 400000000, it still didnt work, do i put a higher number?

Hmm.
I would probably check if any of the parts are anchored.

Probably to debug check if the code is running and check if the BodyGyro works without the stepped function.

none of the parts are anchored, and i get this when using the red circle things, what am i doing wrong here? im new to bodygyros so i dont understand it well
image

Oh wait you also have the CFrame wrong.

local PosAtt = Instance.new("Attachment",workspace.Terrain)
BG.CFrame = PosAtt.CFrame 

instead of that do

local  PosAt = Instance.new("Attachment",workspace.Terrain)
BG.CFrame = CFrame.lookAt(HumanoidRootPart.Position,PosAtt.WorldPosition)

Explanation.
The CFrame works by using the lookat instad of making an entirely new one.
There is a better way to put this I think.
Position and CFrame are not the same thing. CFrame has a position and and orientation.

Also do worldPosition instead of Position usually to get it Relative to the world. Ofcourse in your case you don’t have to because you are setting the parent to the Terrain but I think it is better practice to.

1 Like

oh, now i understand why it didnt work, so the posatt is in terrain with 0,0,0 position and only moves when grabbing an item,

i’ll probably make a fix for it, thanks for helping

1 Like