You can write your topic however you want, but you need to answer these questions:
1. What do you want to achieve? Keep it simple and clear!
I want to add a dash to my R15 Killer NPC, I want to make it so that when my Killer is really close distance to the player, he dashes towards the player and inflicts damage.
2. What is the issue? Include screenshots / videos if possible!
My R15 Killer already has a working pathfinding script, all that is required now is a Dash System for the Killer
This is the PathFindingScript in my Killer
-- Services --
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local PathfindingService = game:GetService("PathfindingService")
-- Variables --
local Character = script.Parent
local Humanoid = Character.Humanoid
local RootPart = Character.HumanoidRootPart
local CanJump = true
local AttackRange = Vector3.new(3, 3, 3)
local FieldOfView = 1000
local CharacterSize = Character:GetExtentsSize()
local PathParams = {
AgentRadius = (CharacterSize.X+CharacterSize.Z)/4,
AgentHeight = CharacterSize.Y,
AgentCanJump = CanJump,
}
-- Functions --
local function GetNearestPlayer()
local players = {}
local nearest = math.huge
local target = nil
for _, player in pairs(Players:GetPlayers()) do
local character = player.Character
if character == nil then
continue
end
local distance = (character.HumanoidRootPart.Position - RootPart.Position)
if distance.Magnitude <= FieldOfView then
table.insert(players, {
Magnitude = distance.Magnitude,
Player = player,
})
end
end
for _, entry in pairs(players) do
local magnitude = entry.Magnitude
local player = entry.Player
if magnitude < nearest then
nearest = magnitude
target = player
end
end
return target
end
-- Connections --
RunService.Heartbeat:Connect(function()
local player = GetNearestPlayer()
if player == nil then
return
end
local player_character = player.Character or player.CharacterAdded:Wait()
local character_humanoid = player_character.Humanoid
if character_humanoid.Health <= 0 then
return
end
if character_humanoid.DisplayName == "KevinEdwardsJr" then
return
end
local target_rootpart = player_character.HumanoidRootPart
local destination = target_rootpart.Position
local beginning = RootPart.Position
local path = PathfindingService:CreatePath(PathParams)
path:ComputeAsync(beginning, destination)
if path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
Humanoid.Jump = true
end
Humanoid:MoveTo(waypoint.Position)
Humanoid.MoveToFinished:Wait()
end
else
Humanoid:MoveTo(RootPart.Position)
end
end)
-- Initialization --
RootPart:SetNetworkOwner(nil)
3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?**
I’ve tried searching through YouTube and DevForum, for an NPC Dash when close to player but haven’t come across a solution.