Now before you link me to some post please note I dont want to use physics, well unless there is a way to do this with physics.
Basically I want a dash ability but I dont want to use some kinda physics cause if you dash into a wall you start bouncing around and your body acts weird and what not, So how can I achieve this?
I use a method that uses runservice and it avoids the usually bouncing into walls and weirdness with jumping. I did not write the script and cannot explain it though.
local _DashDistance = 20
local _DashDuration = 0.4
local _DashSpeed = _DashDistance / _DashDuration
local LastDash = 0
local LastMDirection = Vector3.new()
function EaseQuarticIn(a, b, t, d)
local c = b - a
t /= d
return c * t * t * t * t + a
end
function Lerp(a, b, t)
return a + (b - a) * t
end
function OnRenderStepped()
local DashSpeed = EaseQuarticIn(_DashSpeed, 0, math.min(tick() - LastDash, _DashDuration), _DashDuration)
local DashVelocity = LastMDirection * DashSpeed
local Velocity = Root.AssemblyLinearVelocity
Root.AssemblyLinearVelocity = DashSpeed > 0 and Vector3.new(DashVelocity.X, Velocity.Y, DashVelocity.Z) or Velocity
end
local function Dash(actionName, inputState)
if inputState == Enum.UserInputState.Begin then
if Humanoid.MoveDirection.Magnitude > 0 then -- Won't dash if standing still
local t = tick()
LastDash = t
LastMDirection = Humanoid.MoveDirection
end
end
end
Exactly! I think the best way to do it would be in your attack script or module, create a value and/or variable to detect when the player triggers the attack. Create a Dash function and check if the value is true (it will be true while the attack is running and when it stops, set it to false) then call the function and if it’s not, do nothing. I’ve done something similar to this, but not exact, so I don’t know how well it will work, but I hope it helps you!
--Local Script
local Character = script.Parent
local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
local CanSlide = true
local function Dash()
if not CanSlide then return end
CanSlide = false
local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.MaxForce = Vector3.new(1, 0, 1) * 30000
BodyVelocity.Velocity = HumanoidRootPart.CFrame.LookVector * 100
BodyVelocity.Parent = HumanoidRootPart
for count = 1, 8 do
task.wait(0.1)
BodyVelocity.Velocity *= 0.7
end
BodyVelocity:Destroy()
CanSlide = true
end
--Just for testing as if attacking
local Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.Button1Down:Connect(Dash)
My dodge script will and does work. And unlike your solution mine does not lock the player’s movement for the duration of the dash nor does it slow down near the end of it.