|
| 23 Jun 2016 07:34 PM |
Okay so I'm making an FPS game and this is my camera controlling script, but when I click play and test it it does not follow the mouse properly. Any help is reallllly appreciated.
wait(.5) _G.RecoilY = 0 _G.RecoilX = 0 _G.MouseSensitivity = .1 _G.PrimarySensitivity = .1 _G.SecondarySensitivity = .1 _G.TertiarySensitivity = .1
_G.Target = nil _G.Zoomed = false --game.StarterGui:SetCoreGuiEnabled("Health", false) local RunService = game:GetService("RunService") local RenderStepped = RunService.RenderStepped local UserInputService = game:GetService("UserInputService") UserInputService.MouseBehavior = Enum.MouseBehavior.Default UserInputService.MouseIconEnabled = false -- local Player = game.Players.LocalPlayer local myChar = Player.Character Player.CameraMode = "LockFirstPerson" local Mouse = Player:GetMouse() local Camera = workspace.CurrentCamera Camera.CameraType = "Custom" Camera.FieldOfView = 70 Camera.CameraType = "Custom" Camera:ClearAllChildren() repeat wait() until Player.Character ~= nil repeat wait() until Player.Character:FindFirstChild("Head") ~= nil _G.Target = Player.Character.Head --[[stuff = Player.Character:GetChildren() for i = 1, #stuff do thing = stuff[i] if thing:IsA("Hat") then thing:remove() end end]] xangle = 0 yangle = 0
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter Camera.CameraType = "Scriptable" UserInputService.InputChanged:connect(function(inputObject) local inputObject = inputObject if inputObject.UserInputType == Enum.UserInputType.MouseMovement then local XChange, YChange = inputObject.Delta.X, inputObject.Delta.Y if _G.Zoomed == true then xangle = xangle + YChange*0.005*_G.MouseSensitivity yangle = yangle + XChange*0.005*_G.MouseSensitivity else xangle = xangle + YChange*0.005 yangle = yangle + XChange*0.005 end newxangle = xangle if -xangle+_G.RecoilX > math.rad(89) then xangle = -math.rad(89) _G.RecoilX = 0 Camera.CoordinateFrame = CFrame.new(_G.Target.Position) --Start at the position of the part * CFrame.Angles(0, -yangle+_G.RecoilY, 0) --Rotate by the angle * CFrame.new(0, 0, 0) *CFrame.Angles(-xangle,0,0) elseif -xangle+_G.RecoilX < -math.rad(89) then xangle = math.rad(89) _G.RecoilX = 0 Camera.CoordinateFrame = CFrame.new(_G.Target.Position) --Start at the position of the part * CFrame.Angles(0, -yangle+_G.RecoilY, 0) --Rotate by the angle * CFrame.new(0, 0, 0) *CFrame.Angles(-xangle,0,0) else Camera.CoordinateFrame = CFrame.new(_G.Target.Position) --Start at the position of the part * CFrame.Angles(0, -yangle+_G.RecoilY, 0) --Rotate by the angle * CFrame.new(0, 0, 0) *CFrame.Angles(-xangle+_G.RecoilX,0,0) end
local MDir = Camera.CoordinateFrame.lookVector--mouse.UnitRay.Direction.unit local RotTarget = Vector3.new(MDir.x,0,MDir.z) local cfYaw = CFrame.new(myChar.HumanoidRootPart.Position,myChar.HumanoidRootPart.Position + RotTarget) myChar.HumanoidRootPart.CFrame = cfYaw end end)
RenderStepped:connect(function() if -xangle+_G.RecoilX > math.rad(89) then xangle = -math.rad(89) _G.RecoilX = 0 Camera.CoordinateFrame = CFrame.new(_G.Target.Position) --Start at the position of the part * CFrame.Angles(0, -yangle+_G.RecoilY, 0) --Rotate by the angle * CFrame.new(0, 0, 0) *CFrame.Angles(-xangle,0,0) elseif -xangle+_G.RecoilX < -math.rad(89) then xangle = math.rad(89) _G.RecoilX = 0 Camera.CoordinateFrame = CFrame.new(_G.Target.Position) --Start at the position of the part * CFrame.Angles(0, -yangle+_G.RecoilY, 0) --Rotate by the angle * CFrame.new(0, 0, 0) *CFrame.Angles(-xangle,0,0) else Camera.CoordinateFrame = CFrame.new(_G.Target.Position) --Start at the position of the part * CFrame.Angles(0, -yangle+_G.RecoilY, 0) --Rotate by the angle * CFrame.new(0, 0, 0) *CFrame.Angles(-xangle+_G.RecoilX,0,0) end local MDir = Camera.CoordinateFrame.lookVector--mouse.UnitRay.Direction.unit local RotTarget = Vector3.new(MDir.x,0,MDir.z) local cfYaw = CFrame.new(myChar.HumanoidRootPart.Position,myChar.HumanoidRootPart.Position + RotTarget) myChar.HumanoidRootPart.CFrame = cfYaw end)
--iiPhantomBlue-- |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2016 07:36 PM |
> Posts wall of code > Doesn't define what the script is supposed to be doing and what is happening instead. |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2016 07:46 PM |
Oh sorry, first time posting here. It's basically supposed to make your camera follow your mouse in firstperson when you're holding a gun. I can give a link to the place so you can see the issue I'm talking about a little better?
--iiPhantomBlue-- |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2016 07:48 PM |
| Please do. If it's the first place I don't see the problem. |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2016 07:49 PM |
https://www.roblox.com/games/154630600/Operation-Blox It's this one.
--iiPhantomBlue-- |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2016 07:49 PM |
| "The permission levels on this place prevent you from entering." |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 23 Jun 2016 07:55 PM |
It's on "Everyone" is able to access..and the max players is 18. Idk.
--iiPhantomBlue-- |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2016 07:56 PM |
so, you're trying to do recoil? try out camera rotation if you want it to be smooth, then just do a for i loop, also do a coroutine so it doesn't slow down the fire rate of your gun |
|
|
| Report Abuse |
|
|
| |
|
|
| 23 Jun 2016 07:57 PM |
virulent can you join me? It's really hard to explain this in this thread.
--iiPhantomBlue-- |
|
|
| Report Abuse |
|
|
|
| 23 Jun 2016 07:57 PM |
god dang it i didn't even read it all the way though.. man |
|
|
| Report Abuse |
|
|