So I’ve made a dashing system, but the problem is, if I dash into a wall for example, I fall over.
Code:
local replicated = game:GetService(“ReplicatedStorage”)
local Debree = game:GetService(“Debris”)
local CombatSettings = require(game.ServerScriptService.Modules.Combatmanager)
local DashSettings = CombatSettings.CombatSettings.Dash.Settings
local Event = replicated.Remotes.Combat.Dash
return function(player)
Event.OnServerEvent:Connect(function(Player, DashSignal)
local Char = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local HumanoidRootpart = Char:WaitForChild("HumanoidRootPart")
local function CreateLinear(direction, speed, duration)
local DashSpeed = speed
local Duration = duration
local Front = -1
local Side = 0
local isDashing = true
local DashVelocity = Instance.new("BodyVelocity")
DashVelocity.MaxForce = Vector3.new(math.huge, 0, math.huge)
DashVelocity.P = 1000000
DashVelocity.Parent = HumanoidRootpart
local DashAngularVelocity = Instance.new("BodyAngularVelocity")
DashAngularVelocity.MaxTorque = Vector3.new(3e5, 3e5, 3e5) -- Adjust torque values for turning
DashAngularVelocity.AngularVelocity = Vector3.new(0, 0, 0)
DashAngularVelocity.Parent = HumanoidRootpart
if direction == "DashForward" then
Side = 0
Front = 1
elseif direction == "DashBack" then
Side = 0
Front = -1
elseif direction == "DashRight" then
Side = 1
Front = 0
elseif direction == "DashLeft" then
Side = -1
Front = 0
end
local startTime = tick()
local endTime = startTime + Duration
while isDashing and tick() <= endTime do
local elapsedTime = tick() - startTime
local t = elapsedTime / Duration
DashSpeed = speed * (1 - t)
local currentSpeed = DashSpeed
DashVelocity.Velocity = HumanoidRootpart.CFrame.LookVector * (Front * currentSpeed) + HumanoidRootpart.CFrame.RightVector * (Side * currentSpeed)
DashAngularVelocity.AngularVelocity = Vector3.new(0, math.rad(180), 0) -- Adjust the Y-axis angular velocity for turning
wait()
end
isDashing = false
DashVelocity:Destroy()
DashAngularVelocity:Destroy()
end
if DashSignal == "DashForward" then
CreateLinear("DashForward", 100, .7)
end
if DashSignal == "DashBack" then
CreateLinear("DashBack", 100, .5)
end
if DashSignal == "DashRight" then
CreateLinear("DashRight", 100, .5)
end
if DashSignal == "DashLeft" then
CreateLinear("DashLeft", 100, .5)
end
end)
end
Gif showing the problem:
https://gyazo.com/c2ac4fce2fc5be4d1998c605592887ae
Anyone know how to fix this?
EDIT: I’ve tried setting the HumanoidStateType to both Ragdoll and FallingOver to false, didn’t fix the problem.