My trial to work on Camera Manipulation

I wanted to Script a Camera Manipulation like i saw in the following game link
Dead Ops Arcade (ALPHA) - Roblox

Problem : My character is glitching when i try to move the mouse. The Character should look at the mouse when it moves

The below link is what i have made with the manipulation that glitches

The below script control the Manipulation

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

while wait() do
	if workspace:FindFirstChild(player.Name.."Camera") then -- this is the name of the camera
		workspace.CurrentCamera.CameraType = Enum.CameraType.Track
		workspace.CurrentCamera.CFrame = workspace:FindFirstChild(player.Name.."Camera").CFrame
		local char = player.Character or player.CharacterAdded:Wait()
		local cam = workspace:FindFirstChild(player.Name.."Camera")
		local Root = char:FindFirstChild("HumanoidRootPart")
		cam.CFrame = char:FindFirstChild("HumanoidRootPart").CFrame + Vector3.new(0,50,0)
		cam.Orientation += Vector3.new(-90,0,0)
		mouse.Move:Connect(function()
			Root.CFrame = CFrame.new(Root.Position, Root.Position + Vector3.new(mouse.Hit.lookVector.x, 0, mouse.Hit.lookVector.z))
			wait(.5)
		end)
		print("yes")
	end
	wait()
end

I just scripted this for getting knowledge of camera manipulation, so if u know any solution pls tell me.

Thank you for reading :slight_smile:

2 Likes

Try changing the Character to R6

1 Like

i tried it just now but the character is still glitching

Sorry, but you have to be more clear. Can you provide a visual of the camera manipulation you want to achieve? Hmm, lookvector returns the direction of the mouse’s axis, so if you moving around / orientating, your character would probably have a spasm. I don’t think lookVector is needed in this case because you can just use mouse.Hit.p on each axis, probably with an exception on the Y axis.

Root.CFrame = CFrame.new(Root.Position, Vector3.new(mouse.Hit.p.X, Root.Position.Y, mouse.Hit.p.Z))
1 Like

Sorry, but my pc lags and everything happens very slowly when i try to record something , so i have provided the game links of what i want to script and the game I’ve scripted in the post.

Your given line does the same thing as I’ve scripted. I just need it to be smoother . Btw thanks for the help.

1 Like

Don’t use wait() in the while loop.

I assume this is a client script so I recommend using RunService.HeartBeat:Wait() or RunServer.RenderStepped (all your code will be in this event so no while loop)

2 Likes

Its running more faster and I’m getting errors for that .

Why is there a wait() here even if the the code is inside a while wait do?

1 Like

@Codez_X , @Xx_FROSTBITExX and @Beastcraft_Gaming Thank you all for ur effort of helping me but i have got the solution , I just disconnected the mouse.Move function after a second and its working without any gltiches

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

while wait() do
	if workspace:FindFirstChild(player.Name.."Camera") then
		workspace.CurrentCamera.CameraType = Enum.CameraType.Track
		workspace.CurrentCamera.CFrame = workspace:FindFirstChild(player.Name.."Camera").CFrame
		local char = player.Character or player.CharacterAdded:Wait()
		local cam = workspace:FindFirstChild(player.Name.."Camera")
		local Root = char:FindFirstChild("HumanoidRootPart")
		cam.CFrame = char:FindFirstChild("HumanoidRootPart").CFrame + Vector3.new(0,50,0)
		cam.Orientation += Vector3.new(-90,0,0)
		local connection = mouse.Move:Connect(function()
			Root.CFrame = CFrame.new(Root.Position, Root.Position + Vector3.new(mouse.Hit.lookVector.x, 0, mouse.Hit.lookVector.z))
			wait(.5)
		end)
		wait(1)
		connection:Disconnect()
		print("yes")
	end
end

here is the Code if u want to see. :slight_smile:

3 Likes