i have an npc that rolls towards the closest npc or player using an applyimpulse directed towards the target, but the rolling npc eventually stops moving on its own entirely despite tests showing that the rolling npc still targets and retargets like usual
i’ve also tracked whether or not the impulse is being applied, and shown by the debug prints it does run the functions when it needs to
(positive and negative impulse are printed whenever it runs applyimpulse)
i’m attempting to make it actually work but i could not find any help on the forum about applyimpulse just suddenly not working over time
this is a screenshot of a group of enemies after the applyimpulse bug occurs, shown because the fire on the frontmost npc implies they are still targeting new npcs
screenshot of them (the rolling npcs that look like rocks) doing absolutely nothing
screenshot of applyimpulse working on a projectile despite the bug happening
code sample involving when the applyimpulse is applied
i have tried removing the clamp on their velocity and the bug still happened
local iterations = 0
while target ~= nil and script and script.Enabled == true do
if target ~= nil then
local explosion = Instance.new("Fire")
explosion.Parent = target.HumanoidRootPart
game.Debris:AddItem(explosion, 0.2)
end
local targetpos = target.HumanoidRootPart.Position-Vector3.new(0,3,0)
local dir = (targetpos-script.Parent.Head.Position).Unit
local power = tonumber(attackerhumanoid.WalkSpeed)*500
if atkcooldown == false then
print("positive impulse")
script.Parent.HumanoidRootPart:ApplyImpulse(dir*power)
else
print("negative impulse")
script.Parent.HumanoidRootPart:ApplyImpulse(-dir*power*3)
end
head.AssemblyLinearVelocity = Vector3.new(math.clamp(head.AssemblyLinearVelocity.X,-80,80),math.clamp(head.AssemblyLinearVelocity.Y,-80,80),math.clamp(head.AssemblyLinearVelocity.Z,-80,80))
wait(0.1)
iterations += 1
if target.Humanoid.Health <= 0 or target == nil or target.Parent == workspace.Corpses then
target = nil
end
if iterations >= 25 then
warn("processing retarget")
if target ~= nil then
warn("old target : " .. target.Name)
else
warn("old target : nil")
end
target = nil
while target == nil do
local maxdis = math.huge
local players = nil
local enemies = nil
if coreattacker == true then
players = game.Players:GetPlayers()
enemies = workspace.Allies:GetChildren()
else
players = game.Players:GetPlayers()
enemies = workspace.DeployedEnemies:GetChildren()
end
if coreattacker == true then
for i = 1, #players do
local TargetCharacter = workspace:FindFirstChild(players[i].Name)
local TargetRoot = TargetCharacter:FindFirstChild("HumanoidRootPart")
local dis = (attackerroot.Position - TargetRoot.Position).Magnitude
if dis < maxdis then
maxdis = dis
enemydis = dis
target = TargetCharacter
goalprint = "player"
end--ifdis
wait()
end--for#players
end--ifcoreattacker
for i = 1, #enemies do
local NPCTargetCharacter = enemies[i]
local TargetRoot = NPCTargetCharacter:FindFirstChild("HumanoidRootPart")
if TargetRoot ~= nil then
local npcdis = (attackerroot.Position - TargetRoot.Position).Magnitude
if npcdis < maxdis then
maxdis = npcdis
enemydis = npcdis
target = NPCTargetCharacter
goalprint = "npc"
end--ifdis
end--iftargetroot
wait()
end--for#enemies
wait(0.3)
end--whiletargetnil
warn("new target : " .. target.Name)
iterations = 0
end--ifiterations
end--movementfunction
this is the part of the loop of the entire AI that controls the movement and tracking, target is an instance string, no tables, target is also found before starting this function to clear any confusion
edit: did some extra testing and these are the values used for the impulse while it doesn’t work, they look pretty normal