I am making a samurai fighting game and i want to make my player’s camera move along with the humanoidrootpart when dashing.
Heres the script of the dash:
I’ve tried looking at other threads but none of them had anything about this.
The bool values like “Disabled” and “Hit” are there because of the combat system.
local UIS = game:GetService("UserInputService")
local Remote = script:WaitForChild("Remote")
Remote:FireServer()
local camera = workspace.CurrentCamera
local DKeyDown = false
local SKeyDown = false
local AKeyDown = false
local WKeyDown = false
local CameraShaker = require(game:GetService('ReplicatedStorage'):WaitForChild("CameraShaker"));
local camShake = CameraShaker.new(Enum.RenderPriority.Camera.Value, function(shakeCf)
camera.CFrame = camera.CFrame * shakeCf
end)
local Blocking = false
camShake:Start()
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
while Char.Parent == nil do
Char.AncestryChanged:wait()
end
local HumRP = Char:WaitForChild("HumanoidRootPart")
local Hum = Char:WaitForChild("Humanoid")
local RollFrontAnim = Hum:LoadAnimation(script:WaitForChild("RollFront"))
local BackRollAnim = Hum:LoadAnimation(script:WaitForChild("BackRoll"))
local LeftRollAnim = Hum:LoadAnimation(script:WaitForChild("RightRoll"))
local RightRollAnim = Hum:LoadAnimation(script:WaitForChild("LeftRoll"))
local DashDebounce = false
local DashingDebounce = false
local CanDoAnything = true
UIS.InputBegan:Connect(function(Input,IsTyping)
if IsTyping then return end
if CanDoAnything == true then
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
Remote:FireServer("Slash")
elseif Input.KeyCode == Enum.KeyCode.E then
Remote:FireServer("Equip")
elseif Input.KeyCode == Enum.KeyCode.Q then
if DashDebounce == false and Char:FindFirstChild("Disabled") == nil then
DashDebounce = true
CanDoAnything = false
delay(0.3,function()
CanDoAnything = true
end)
delay(1.5,function()
DashDebounce = false
end)
if WKeyDown then
RollFrontAnim:Play()
DashingDebounce = true
delay(0.25,function()
DashingDebounce = false
end)
repeat
HumRP.Velocity = HumRP.CFrame.lookVector * 70
wait(0.05)
until DashingDebounce == false
elseif SKeyDown then
BackRollAnim:Play()
DashingDebounce = true
delay(0.25,function()
DashingDebounce = false
end)
repeat
HumRP.Velocity = HumRP.CFrame.lookVector * -70
wait(0.05)
until DashingDebounce == false
elseif DKeyDown then
RightRollAnim:Play()
DashingDebounce = true
delay(0.25,function()
DashingDebounce = false
end)
repeat
HumRP.Velocity = HumRP.CFrame.rightVector * 70
wait(0.05)
until DashingDebounce == false
elseif AKeyDown then
LeftRollAnim:Play()
DashingDebounce = true
delay(0.25,function()
DashingDebounce = false
end)
repeat
HumRP.Velocity = HumRP.CFrame.rightVector * -70
wait(0.05)
until DashingDebounce == false
end
end
elseif Input.UserInputType == Enum.UserInputType.MouseButton2 then
if UIS.MouseBehavior == Enum.MouseBehavior.LockCenter then
Remote:FireServer("Heavy")
end
end
end
end)
local RunService = game:GetService("RunService")
RunService.RenderStepped:Connect(function()
local Player = game.Players.LocalPlayer
local Char = Player.Character
local Hum = Char:FindFirstChild("Humanoid")
if UIS:IsKeyDown(Enum.KeyCode.F) then
if CanDoAnything == true then
if Blocking == false then
Blocking = true
Remote:FireServer("Block",true)
end
end
else
if Blocking == true then
Blocking = false
Remote:FireServer("Block",false)
end
end
if UIS:IsKeyDown(Enum.KeyCode.W) then
WKeyDown = true
else
WKeyDown = false
end
if UIS:IsKeyDown(Enum.KeyCode.A) then
AKeyDown = true
else
AKeyDown = false
end
if UIS:IsKeyDown(Enum.KeyCode.S) then
SKeyDown = true
else
SKeyDown = false
end
if UIS:IsKeyDown(Enum.KeyCode.D) then
DKeyDown = true
else
DKeyDown = false
end
-- Yessir
end)
Remote.OnClientEvent:Connect(function(Action)
if Action == "HeavyShake" then
camShake:Shake(CameraShaker.Presets.HeavyHit)
else
camShake:Shake(CameraShaker.Presets.SwordHit)
end
end)