Currently, I Have a prototype dash in my game, which does not stop near a NPC or player and instead will push through them if directed at them. (You can test this with the NPC’s near your spawn)
You could have a box, similar to a hitbox, but only for the sole purpose of seeing if other players are in a certain radius. Then you could you use get parts in part to check to see whether other characters are in that box while dashing.
My problem with this is that actually stopping the dash is going to be hard for me,
This is the function I use for my dashes.
local function BodyVelocityApply(Times,Factor,Duration)
local BodyVelocity = Instance.new("BodyVelocity",RootPart)
BodyVelocity.MaxForce = Vector3.new(math.huge, 0, math.huge)
local CurrentDirection = nil
if Left or UserInputService:IsKeyDown(Enum.KeyCode.A) then
CurrentDirection = "Left"
elseif Right or UserInputService:IsKeyDown(Enum.KeyCode.D) then
CurrentDirection = "Right"
elseif Front or UserInputService:IsKeyDown(Enum.KeyCode.W) then
CurrentDirection = "Front"
elseif Back or UserInputService:IsKeyDown(Enum.KeyCode.S) then
CurrentDirection = "Back"
end
for i = Times, 0, Factor do
if CurrentDirection == "Left" then
BodyVelocity.Velocity = Character.HumanoidRootPart.CFrame.RightVector * -i
elseif CurrentDirection == "Right" then
BodyVelocity.Velocity = Character.HumanoidRootPart.CFrame.RightVector * i
elseif CurrentDirection == "Back" then
BodyVelocity.Velocity = Character.HumanoidRootPart.CFrame.LookVector * -i
elseif CurrentDirection == "Front" then
BodyVelocity.Velocity = Character.HumanoidRootPart.CFrame.LookVector * i
end
wait(Duration)
end
BodyVelocity:Destroy()
end
How would I Stop a Bodyvelocity Mid Dash?
Lets say this hitbox fires a bindable or event when it detects a nearby humanoid, how would I make that alter the body velocity or even completly stop it
You could do one of two things, you can either just automatically destroy the body velocity when that happens or lower the body velocity to something like i - 10 when a player enters the box
Idk, the first thing that comes to mind too smoothly stop the dash is something like:
Create a BodyVelocity and set it to the opposite AssemblyLinearVelocity of HumanoidRootPart
Create a variable that goes times the AssemblyLinearVelocity.
And then adjust the smooth variable to stop definitely the player.
like:
--Supposing you already created and configurated the new BodyVelocity:
local smooth = 50
for i = 1,50,1 do
smooth -= 1
newBodyVelocity.Velocity = -Character.HumanoidRootPart.AssemblyVelocity * smooth
end
I am currently working on reworking the bodyvelocity application to make it easier to stop,
Once im done, Ill try this because it sounds like a pretty good idea
A hacky way of doing this would be to place your main dash function in a thread. You’ll also create a hitbox x studs in front of the HRP and with this you’ll constantly check if another player is detected. If detected, you’ll cancel the thread and delete the hitbox. It makes sense in my mind idk if you can see my vision
local function BodyVelocityApply(Times,Factor,Duration)
local BodyVelocity = Instance.new("BodyVelocity",RootPart)
BodyVelocity.MaxForce = Vector3.new(math.huge, 0, math.huge)
local CurrentDirection = nil
if Left or UserInputService:IsKeyDown(Enum.KeyCode.A) then
CurrentDirection = "Left"
elseif Right or UserInputService:IsKeyDown(Enum.KeyCode.D) then
CurrentDirection = "Right"
elseif Front or UserInputService:IsKeyDown(Enum.KeyCode.W) then
CurrentDirection = "Front"
elseif Back or UserInputService:IsKeyDown(Enum.KeyCode.S) then
CurrentDirection = "Back"
end
for i = Times, 0, Factor do
if HumanoidClose == false then
if CurrentDirection == "Left" then
BodyVelocity.Velocity = Character.HumanoidRootPart.CFrame.RightVector * -i
elseif CurrentDirection == "Right" then
BodyVelocity.Velocity = Character.HumanoidRootPart.CFrame.RightVector * i
elseif CurrentDirection == "Back" then
BodyVelocity.Velocity = Character.HumanoidRootPart.CFrame.LookVector * -i
elseif CurrentDirection == "Front" then
BodyVelocity.Velocity = Character.HumanoidRootPart.CFrame.LookVector * i
end
wait(Duration)
else
break
end
end
BodyVelocity:Destroy()
end
local function DetectHumanoids(RootPart,Humanoid,Size,Offset,Duration)
local Hitbox = HitboxModule.CreateHitbox()
Hitbox.Size = Size
Hitbox.Offset = Offset
Hitbox.CFrame = RootPart
Hitbox.Touched:Connect(function(Part)
local Enemy = Part.Parent
local EnemyHumanoid = Enemy:WaitForChild("Humanoid")
if EnemyHumanoid ~= Humanoid then
HumanoidClose = true
task.wait(0.3)
HumanoidClose = false
end
end)
Hitbox:Start()
task.wait(Duration)
Hitbox:Stop()
end