Hello! I’m trying to make a dash ability skill, but you can charge it to make the dash travel longer. So the problem I have right now is trying to show the player where he will end up accurately. I tried to search up for it on DevForum but couldnt find anything that could help me.
For dash I use BodyVelocity
and for visualisating I use Beam
.
Please, keep in mind that all scripts below are just summary of how it works
Dash script
function Dash(Config: {Dir: Vector3, Power: number, Time: number})
local Character = Player.Character
local HumanoidRootPart = Character.HumanoidRootPart
local RootAttachment = HumanoidRootPart.RootAttachment
if not Config.Dir then
Config.Dir = HumanoidRootPart.CFrame.LookVector
end
if HumanoidRootPart:FindFirstChild("KBV") then
HumanoidRootPart.KBV:Destroy()
end
local KBV = Instance.new("BodyVelocity")
KBV.Name = "KBV"
KBV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
KBV.Velocity = Config.Dir * (Config.Power)
KBV.Parent = HumanoidRootPart
Debris:AddItem(KBV, Config.Time or 0.1)
end
Beam script
function ShowBeam(StartLength: number, EndLength: number, Step: number)
if not Step then Step = 1 end
local CurrentLength = StartLength
local Beam = Effects.AimBeam:Clone()
local A0 = Instance.new("Attachment")
A0.Name = "VA0"
local A1 = Instance.new("Attachment")
A1.Name = "VA1"
A0.Position = Vector3.new(0, -2.9, 0)
A0.Orientation = Vector3.new(0, 0, 90)
A0.Parent = Player.Character.HumanoidRootPart
A1.Position = Vector3.new(0, -2.9, -CurrentLength)
A1.Orientation = Vector3.new(0, 0, 90)
A1.Parent = Player.Character.HumanoidRootPart
Beam.Parent = A0
Beam.Attachment0 = A0
Beam.Attachment1 = A1
while Beam and Beam.Parent and CurrentLength < EndLength do
local DeltaTime = RunService.Heartbeat:Wait()
CurrentLength += Step * DeltaTime
if CurrentLength > EndLength then CurrentLength = EndLength end
A1.Position = Vector3.new(0, -2.9, -CurrentLength)
end
end
Ability script
local StartPower = 30
local PassedTime = 0
task.spawn(ShowBeam, 6, 20)
while Character:GetAttribute("Charging") == true do
local DeltaTime = RunService.Heartbeat:Wait()
PassedTime += DeltaTime
end
Player.Character.HumanoidRootPart.VA0:Destroy()
Player.Character.HumanoidRootPart.VA1:Destroy()
local NewPower = math.clamp(30 + PassedTime, 0, 100)
Dash({Power = NewPower, Time = 0.2})
Here’s a video of how it looks