Gun aiming with aimpart - Cant move mouse

Hello, i’m trying to do aiming by Camera.CFrame = AimPart.CFrame. I got a problem that i cannot move mouse while aiming
.update: in first person i just randomly rotating with no reason

Code:

RunService.Stepped:Connect(function()
	if Equipped == true and Hold2 == true or Hold2 == false then
		if Hold2 == true then
			UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
			camera.CameraType = Enum.CameraType.Scriptable
			camera.CFrame = Tool.AimPoint.CFrame
		elseif Hold2 == false then
			camera.CameraType = Enum.CameraType.Custom
		end
	end
end)

Video:


Video2:

I’m trying to move mouse to a left or right but it didn’t work.
Maybe I don’t understand something. but I would really appreciate help solving this problem

Instead of moving the camera, you have to move the tool/viewmodel

i dont want to use viewmodel, i trying to achive aiming like R2D (Camera move to aimpart you can see this in a part when i stand next to a wall)

1 Like

That, looks like a viewmodel to me

Standing next to wall, gun is out of wall. That’s definitely camera goes to aimpart

Whats the camera mode set to in the starterPlayer folder? (Classic or LockFirstPerson?)

Interesting could try setting humanoid camera offset property instead then since it is offset from the head.

You should be able to calculate this as (aimpoint.Position - humanoid.Head.Position)

Something like this? if i understand you correctly.

Humanoid.CameraOffset = Tool.AimPoint.Position - Humanoid.Head.Position

Result i get.

CameraOffset is relative to the Character HumanoidRootPart, you need to get the Offset between the Head CFrame and the AimPart CFrame. And then set the Humanoid CameraOffset to ThatCFrame.Position.

local Offset = Head.CFrame:toObjectSpace(AimPart.CFrame)
Humanoid.CameraOffset = Offset.Position

This code should work.

1 Like

This is not exactly what I need, I need the camera to be in the aimpart position

Check the first video. I hope it will be clearer what I mean.
Result i have with your script (I have moving arms script btw but i checked without it and its not what i need)

Maybe this will also clarify my question. The result I want to achieve (in the example, the camera also goes to “AimPart”)
Video:


Or this:

1 Like

I know what you meant, but did you put the script i provided on a loop? It has to be in a loop to work properly

Oh i forgot to delete “camera.CameraType = Enum.CameraType.Scriptable”
That’s work perfectly! Thank you very much!

1 Like

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