Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does making the camera look down on your character prevent character movement?

I'm trying to create a script that makes the camera look down on your character from above, from a bird's eye view. My method is to create a part that looks down on your character and set the camera's CoordinateFrame to that part.

Although the camera gets placed in the correct position, my character will not move when I press either WASD or the arrow keys.

My character does have the ability to move, that is, I can set the WalkToPoint manually and my character will walk around. It will not, however, move when I use the buttons on my keyboard.

There are no errors in the output. All answers are appreciated.

The following is a LocalScript inside StarterGui.

local cam = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
	repeat wait() until plr.Character
local chr = plr.Character
local torso = chr:WaitForChild("Torso")

--Part
local part = Instance.new("Part",chr)
part.Size = Vector3.new(1,1,1)
part.Anchored = true
part.Transparency = 1
part.CanCollide = false
part.Name = "CameraControlPart"

--Set camera
cam.CameraType = "Scriptable"
cam.CameraSubject = chr:WaitForChild("Humanoid")

--Main loop
game:GetService("RunService").RenderStepped:connect(function()
	--Part CFrame	
	part.CFrame = CFrame.new(
		Vector3.new(	--Position
			torso.Position.x,
			torso.Position.y + 10,
			torso.Position.z),
		torso.Position  --Look at	
		)		

	--Camera CFrame
	cam.CoordinateFrame = part.CFrame
end)

1 answer

Hello! I think this is the outcome you wanted originally.

The problem was that the camera was getting stuck on the character and in turn made the character stuck. I fixed this by adding a slight offset to the look vector which I don't think is noticeable. If it is you probably make it smaller.

If you need more clarifying feel free to ask.

local cam = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
    repeat wait() until plr.Character
local chr = plr.Character
local torso = chr:WaitForChild("Torso")

--Set camera
cam.CameraType = "Scriptable"
cam.CameraSubject = chr:WaitForChild("Humanoid")

game:service'RunService'.RenderStepped:connect(function()
	
	cam.CoordinateFrame = CFrame.new(
		Vector3.new(0,10,0) + torso.Position,
		torso.Position + Vector3.new(1,0,0)
	)
end)

To see what I mean about it getting stuck: use this code and make your character get close to the center of the camera.

local cam = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
    repeat wait() until plr.Character
local chr = plr.Character
local torso = chr:WaitForChild("Torso")

--Set camera
cam.CameraType = "Scriptable"
cam.CameraSubject = chr:WaitForChild("Humanoid")

game:service'RunService'.RenderStepped:connect(function()
	
	cam.CoordinateFrame = CFrame.new(
		Vector3.new(0,10,0),
		torso.Position
	)
end)

1 comment

0

That works, and you're right, it's a better method, but why does setting the camera directly above the character make him/her get stuck?

This discussion is preserved as it was. New answers, comments, and votes are closed.