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

Free cam, camera CFRAME glitchy? [closed]

Asked by 7 years ago
Edited 7 years ago
player = game.Players.LocalPlayer
mouse = player:GetMouse()
camera = game.Workspace.CurrentCamera
UserInputService = game:GetService("UserInputService")

wait(2)

game.Players.LocalPlayer.Character:Destroy()

camera.CameraType = "Scriptable"
camera.CoordinateFrame = CFrame.new(0,18,0)

keys = {}

mouse.KeyDown:connect(function(key) keys[key] = true end)
mouse.KeyUp:connect(function(key) keys[key] = nil  end)




UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
UserInputService.InputChanged:connect(function(inputObject)
    if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
        print("delta is (" .. tostring(inputObject.Delta.x) .. ", " ..  tostring(inputObject.Delta.y) .. ")")
        camera.CoordinateFrame = CFrame.Angles(0,math.rad(-inputObject.Delta.x),0) * CFrame.Angles(math.rad(-inputObject.Delta.y),0,0) * camera.CoordinateFrame 

-- glitches here
    end
end)

game:GetService("RunService").RenderStepped:connect(function()

--Basic Moving


if keys["w"] then
camera.CoordinateFrame  = camera.CoordinateFrame * CFrame.new(0,0,-1)   
end

if keys["s"] then
camera.CoordinateFrame  = camera.CoordinateFrame * CFrame.new(0,0,1)    
end

if keys["a"] then
camera.CoordinateFrame  = camera.CoordinateFrame * CFrame.new(-1,0,0)   
end

if keys["d"] then
camera.CoordinateFrame  = camera.CoordinateFrame * CFrame.new(1,0,0)    
end


--Basic Moving

end)

If you use it and look around, its very weird and "rolls"

Closed as Non-Descriptive by antonio6643

This question has been closed because its title or content does not adequately describe the problem you are trying to solve.
Please ensure that your question pertains to your actual problem, rather than your attempted solution. That is, you were trying to solve problem X, and you thought solution Y would work, but instead of asking about X when you ran into trouble, you asked about Y.

Why was this question closed?

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

This should give you the same camera as the one you use in studio. That means that you won't have to code controls for it. The control keys are WASDQE

Put this in a LocalScript in Game.StarterPlayer.StarterPlayerScripts

local player = game.Players.LocalPlayer
wait(1)
Camera = game.Workspace.CurrentCamera
game:GetService('RunService').RenderStepped:connect(function()
Camera.CameraType = 'Fixed'
Camera.CameraSubject = workspace
end)

And put this in a Script in Game.Workspace

function remove_character(child)
if game.Players:playerFromCharacter(child) ~= nil then
    repeat wait() until child:findFirstChild("Torso")
    game.Players:playerFromCharacter(child).Character = nil
end end

game.Workspace.ChildAdded:connect(remove_character)
for x, v in pairs(game.Workspace:getChildren()) do
    remove_character(v)
end

The Script removes the players Character as soon as it is created. The LocalScript changes the camera to

Camera.CameraType = 'Fixed' Camera.CameraSubject = workspace

every time a new frame is rendered. This is important because without it Roblox would automatically reset it to the defaults.

Ad