i’m making a sliding mechanic, everything works really nice but the camera cframe change
in third person it works fine (minus the avatar wearables being visible)
but in first person it just spazzes out
to clarify, no, i do not want third person to be fixed, as the game will not support 3rd person
preview of what’s happening:
local plr = game:GetService("Players").LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local debounce = false
local connection = nil
local UIS = game:GetService("UserInputService")
local event = game:GetService("ReplicatedStorage"):WaitForChild("PlayerEvents").SlideEvent
local Anim = script:WaitForChild("SlideAnim")
local Camera = workspace:WaitForChild("Camera")
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.LeftControl and Humanoid.WalkSpeed > 16 then
if debounce then return end
debounce = true
event:FireServer()
local animator = Humanoid:FindFirstChildOfClass("Animator")
if not animator then return end
local Slide = animator:LoadAnimation(Anim)
Slide:Play()
connection = game:GetService("RunService").RenderStepped:Connect(function()
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Char.Head.CFrame
end)
Slide.Ended:Wait()
connection:Disconnect()
Camera.CameraType = Enum.CameraType.Custom
task.wait(1)
debounce = false
end
end
end)
prob add a part on top if your character’s head that only moves in the z axis (a while loop should work), set your camera’s cframe to it, when the sliding anim ends destroy it and set ur cam back to normal
i’m gonna be honest i didn’t really use a while loop because i didn’t really know what you meant by it (), but this is what i did:
if input.KeyCode == Enum.KeyCode.LeftControl and Humanoid.WalkSpeed > 16 then
if debounce then return end
debounce = true
event:FireServer()
local animator = Humanoid:FindFirstChildOfClass("Animator")
if not animator then return end
local Slide = animator:LoadAnimation(Anim)
Slide:Play()
local FOVIncrease = TS:Create(Camera, TweenInfo.new(0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {FieldOfView = 110})
local FOVDecrease = TS:Create(Camera, TweenInfo.new(0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {FieldOfView = 90})
FOVIncrease:Play()
FOVIncrease.Completed:Wait()
FOVDecrease:Play()
local Part = Instance.new("Part")
Part.Parent = Char.Head
Part.Transparency = 1
Part.CanCollide = false
Part.Anchored = true
connection = game:GetService("RunService").RenderStepped:Connect(function() -- i assume doing this is the error, but i wouldn't know
Part.CFrame = Char.Head.CFrame
Camera.CFrame = Part
end)
Slide.Ended:Wait()
connection:Disconnect()
-- destroy here!!
Camera.CameraType = Enum.CameraType.Custom
task.wait(1)
debounce = false
end
It might be because you’re changing CameraType every frame, try this
local plr = game:GetService("Players").LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local debounce = false
local connection = nil
local UIS = game:GetService("UserInputService")
local event = game:GetService("ReplicatedStorage"):WaitForChild("PlayerEvents").SlideEvent
local Anim = script:WaitForChild("SlideAnim")
local Camera = workspace:WaitForChild("Camera")
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.LeftControl and Humanoid.WalkSpeed > 16 then
if debounce then return end
debounce = true
event:FireServer()
local animator = Humanoid:FindFirstChildOfClass("Animator")
if not animator then return end
local Slide = animator:LoadAnimation(Anim)
Slide:Play()
Camera.CameraType = Enum.CameraType.Scriptable
connection = game:GetService("RunService").RenderStepped:Connect(function()
Camera.CFrame = Char.Head.CFrame
end)
Slide.Ended:Wait()
connection:Disconnect()
Camera.CameraType = Enum.CameraType.Custom
task.wait(1)
debounce = false
end
end
end)
(This is an assumption and probably won’t work but I don’t see anything particularly wrong with your code)
though i don’t necessarily expect myself to be using CameraType.Scriptable as i do want to allow the player to turn during the slide (unless there’s a way to code that in)
setting it above breaks the camera so i didn’t record a preview,
however note that the camera breaks after that (the bobbling actually makes the player walk sideways, and going into third person makes the camera follow the player’s head, though the third person issue isn’t really something i care about)
this is my first time using BindToRenderStep, so i’m not even sure if this code is correct:
game:GetService("RunService"):BindToRenderStep("moveCamera", 30, function()
Camera.CFrame = Char.Head.CFrame
end)
Slide.Ended:Wait()
game:GetService("RunService"):UnBindFromRenderStep("moveCamera") -- i should probably store run service in a variable lol
task.wait(1)
debounce = false
local c = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local p = Instance.new("Part", c)
p.Name = "theGloriousPart"
p.Anchored = true
p.Transparency = 1
p.CanCollide = false
p.Position = c.Head.Position + Vector3.new(0,3,0)
local a = false
game.UserInputService.InputBegan:Connect(function(i)
if i.KeyCode == Enum.KeyCode.E then
workspace.CurrentCamera.CameraType = "Scriptable"
a = false
task.spawn(function()
while task.wait() do
workspace.CurrentCamera.CFrame = p.CFrame
if a then
break
end
end
end)
task.wait(2)
a = true
workspace.CurrentCamera.CameraType = "Custom"
workspace.CurrentCamera.CFrame = c.Head.CFrame
end
end)
while true do
p.Position = c.Head.Position + Vector3.new(0,3,0)
local c = workspace.CurrentCamera.CFrame - workspace.CurrentCamera.CFrame.Position + p.Position;
p.CFrame = c
task.wait()
end
i’ve made a simple script that moves your camera’s cframe to the new part, change the task.wait(2) to task.wait(anim.Length)