Stop camera from moving when holding onto a ledge?
So while working on my game i came upon two problems that i don't find a way to fix. The first problem is that when the player is holding onto an edge i want him to be able to move his head in each direction a bit ( not to be able to do a 360 ) and not his entire body like roblox def settings do. The second problem i found is that when the player is holding on a ledge the left arm animation is glitching , i tried remaking the anim but still doesn't work. Also the game is first person only.
Here is the ledge grabbing script :
P.S i tried using the CameraType but doesnt work.
01 | local plr = game.Players.LocalPlayer |
02 | local Character = plr.Character or plr.CharacterAdded:Wait() |
03 | local Root = Character:WaitForChild( "HumanoidRootPart" ) |
04 | local Head = Character:WaitForChild( "Head" ) |
05 | local Hum = Character:WaitForChild( "Humanoid" ) |
06 | local CA = Hum:LoadAnimation(script:WaitForChild( "ClimbAnim" )) |
07 | local HA = Hum:LoadAnimation(script:WaitForChild( "HoldAnim" )) |
08 | local TouchGui = plr:WaitForChild( "PlayerGui" ):FindFirstChild( "TouchGui" ) |
09 | local UIS = game:GetService( "UserInputService" ) |
10 | local Camera = workspace.CurrentCamera |
15 | while game:GetService( "RunService" ).Heartbeat:Wait() do |
16 | local r = Ray.new(Head.CFrame.p, Head.CFrame.LookVector * 5 ) |
17 | local part,position = workspace:FindPartOnRay(r,Character) |
19 | if part and ledgeavailable and not holding then |
20 | if part.Size.Y > = 7 then |
21 | if Head.Position.Y > = (part.Position.Y + (part.Size.Y / 2 )) - 1 and Head.Position.Y < = part.Position.Y + (part.Size.Y / 2 ) and Root.Velocity.Y < = 0 then |
22 | Root.Anchored = true holding = true HA:Play() ledgeavailable = false |
28 | local Vele = Instance.new( "BodyVelocity" ,Root) |
30 | Vele.MaxForce = Vector 3. new( 1 , 1 , 1 ) * math.huge |
31 | Vele.Velocity = Root.CFrame.LookVector * 10 + Vector 3. new( 0 , 30 , 0 ) |
33 | game.Debris:AddItem(Vele,. 15 ) |
39 | UIS.InputBegan:Connect( function (Key,Chat) |
40 | if not holding then return end |
41 | if Key.KeyCode = = Enum.KeyCode.Space and not Chat then |
47 | TouchGui:WaitForChild( "TouchControlFrame" ):WaitForChild( "JumpButton" ).MouseButton 1 Click:Connect( function () |
48 | if not holding then return end climb() |
55 | if holding = = true then |
and here is the first person camera script :
001 | repeat wait() until game:GetService( "Players" ).LocalPlayer.Character ~ = nil |
002 | local runService = game:GetService( "RunService" ) |
003 | local input = game:GetService( "UserInputService" ) |
004 | local players = game:GetService( "Players" ) |
006 | CanToggleMouse = { allowed = true ; activationkey = Enum.KeyCode.F; } |
011 | local cam = game.Workspace.CurrentCamera |
012 | local player = players.LocalPlayer |
013 | local m = player:GetMouse() |
015 | local character = player.Character or player.CharacterAdded:wait() |
016 | local humanoidpart = character.HumanoidRootPart |
018 | local head = character:WaitForChild( "Head" ) |
019 | local CamPos,TargetCamPos = cam.CoordinateFrame.p,cam.CoordinateFrame.p |
020 | local AngleX,TargetAngleX = 0 , 0 |
021 | local AngleY,TargetAngleY = 0 , 0 |
024 | local freemouse = false |
028 | if not character or not character.Parent then |
029 | character = player.CharacterAdded:wait() |
031 | local humanoid = character:WaitForChild( "Humanoid" ) |
032 | local torso = character:WaitForChild( "Torso" ) |
033 | local rightShoulder = torso:WaitForChild( "Right Shoulder" ) |
034 | local leftShoulder = torso:WaitForChild( "Left Shoulder" ) |
035 | local rootpart = character:WaitForChild( "HumanoidRootPart" ) |
042 | for _, v in pairs (character:GetChildren()) do |
044 | if v.Name = = 'Head' then |
045 | v.LocalTransparencyModifier = 1 |
049 | if v:IsA 'Part' or v:IsA 'UnionOperation' or v:IsA 'MeshPart' then |
050 | v.LocalTransparencyModifier = 1 |
054 | if v:IsA 'Accessory' then |
055 | v:FindFirstChild( 'Handle' ).LocalTransparencyModifier = 1 |
056 | v:FindFirstChild( 'Handle' ).CanCollide = false |
059 | v:FindFirstChild( 'Handle' ).LocalTransparencyModifier = 1 |
060 | v:FindFirstChild( 'Handle' ).CanCollide = false |
067 | input.InputChanged:connect( function (inputObject) |
069 | if inputObject.UserInputType = = Enum.UserInputType.MouseMovement then |
070 | local delta = Vector 2. new(inputObject.Delta.x/Sensitivity,inputObject.Delta.y/Sensitivity) * Smoothness |
072 | local X = TargetAngleX - delta.y |
073 | TargetAngleX = (X > = 80 and 80 ) or (X < = - 80 and - 80 ) or X |
074 | TargetAngleY = (TargetAngleY - delta.x) % 360 |
079 | input.InputBegan:connect( function (inputObject) |
081 | if inputObject.UserInputType = = Enum.UserInputType.Keyboard then |
082 | if inputObject.KeyCode = = CanToggleMouse.activationkey then |
083 | if CanToggleMouse.allowed and freemouse = = false then |
093 | runService.RenderStepped:connect( function () |
098 | CamPos = CamPos + (TargetCamPos - CamPos) * 0.28 |
099 | AngleX = AngleX + (TargetAngleX - AngleX) * 0.35 |
100 | local dist = TargetAngleY - AngleY |
101 | dist = math.abs(dist) > 180 and dist - (dist / math.abs(dist)) * 360 or dist |
102 | AngleY = (AngleY + dist * 0.35 ) % 360 |
103 | cam.CameraType = Enum.CameraType.Scriptable |
105 | cam.CoordinateFrame = CFrame.new(head.Position) |
106 | * CFrame.Angles( 0 ,math.rad(AngleY), 0 ) |
107 | * CFrame.Angles(math.rad(AngleX), 0 , 0 ) |
108 | * CFrame.new( 0 , 0.8 , 0 ) |
110 | humanoidpart.CFrame = CFrame.new(humanoidpart.Position)*CFrame.Angles( 0 ,math.rad(AngleY), 0 ) |
111 | character.Humanoid.AutoRotate = false |
112 | else game:GetService( "UserInputService" ).MouseBehavior = Enum.MouseBehavior.Default; character.Humanoid.AutoRotate = true |
115 | if (cam.Focus.p-cam.CoordinateFrame.p).magnitude < 1 then |
119 | if freemouse = = true then |
120 | game:GetService( "UserInputService" ).MouseBehavior = Enum.MouseBehavior.Default |
122 | game:GetService( "UserInputService" ).MouseBehavior = Enum.MouseBehavior.LockCenter |
126 | if not CanToggleMouse.allowed then |
135 | game:GetService( "RunService" ).RenderStepped:Connect( function () |
136 | character [ "Right Arm" ] .LocalTransparencyModifier = character [ "Right Arm" ] .Transparency |
137 | character [ "Left Arm" ] .LocalTransparencyModifier = character [ "Left Arm" ] .Transparency |
138 | local camCF = cam.CoordinateFrame |
139 | local distance = (character.Head.Position - camCF.p).magnitude |
140 | if distance < = 2 and humanoid.Health ~ = 0 then |
141 | rightShoulder.C 0 = rightShoulder.C 0 :lerp((camCF * CFrame.new( 1 , - 1 , -. 5 )):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles( 0 , math.pi/ 2 , 0 ), updateSpeed) |
142 | leftShoulder.C 0 = leftShoulder.C 0 :lerp((camCF * CFrame.new(- 1 , - 1 , -. 5 )):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles( 0 , -math.pi/ 2 , 0 ), updateSpeed) |
143 | humanoid.CameraOffset = (rootpart.CFrame+Vector 3. new( 0 , 1.5 , 0 )):pointToObjectSpace(head.CFrame.p) |
145 | rightShoulder.C 0 = CFrame.new( 1 , 0.5 , 0 ) * CFrame.Angles( 0 , math.pi/ 2 , 0 ) |
146 | leftShoulder.C 0 = CFrame.new(- 1 , 0.5 , 0 ) * CFrame.Angles( 0 , -math.pi/ 2 , 0 ) |
147 | humanoid.CameraOffset = Vector 3. new( 0 , 0 , 0 ) |
If someone can help me it would be awesome.