Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

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

Log in to vote
0
Answered by 9 years ago

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)
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? Perci1 4988 — 9y
Ad

Answer this question