#Enemy AI

1 messages · Page 1 of 1 (latest)

crystal copper
#

My enemy AI works but it is really buggy right now especially since, whenever it attacks, it teleports towards the play makeing very choppy animations and gameplay

#

The part for enemy AI is in the HuntTarget Function

dreamy tree
#

well you are teleporting the ai

#

to the player

#

Imma send my attack logic for you

#

one sec

#
while os.clock() - Start < 15 and Distance < GRANDMA_CONFIG.MaximumDistance do

        Humanoid:MoveTo(Closest.PrimaryPart.Position + Closest.Humanoid.MoveDirection * 3)

        local newClosest, newDistance = self:FindClosestCharacter()
        Distance = newDistance
        
        if newClosest ~= Closest then break end
        if Closest:GetAttribute("Invisible") then break end
        
        if Distance < GRANDMA_CONFIG.HitDistance then
            print("Killed player")
            Closest.Humanoid.Health = 0
            Closest.PrimaryPart.AssemblyLinearVelocity = Vector3.new(math.random(1, 9) * 10, 100, math.random(1, 9) * 10)
            break
        end

        if self:InLineOfSight(Closest) then
            Lost = os.clock()
        end

        if os.clock() - Lost > 4 then
            print("lost player")
            break
        end

        task.wait()
    end```
#

its pretty similar to what you have

#

the only difference is some knockback and other thinggs

#

also

#

For the moveto part, to make sure the ai will always before infront of the player

#

or close to it

#

I take into account the Movedirection, and make it so it tries to move infront of the players current position

clever glacier
#

i would recommend setting networkownership to the player being chased

#

to avoid network latency for that player

crystal copper
#

k I'll try it out

crystal copper
#

Thanks, finally got a decent system for it to work, not really sure about the whole networkownership thing yet though

#

Problem is right now, whenever I do a huge burst of velocity/movement with my slide ability, it causes the enemy to follow with a huge burst of movement to follow me

dreamy tree
#

I forgot to do that in my own script

#

but didn't affect it as much because I don't have a dash ability

crystal copper
#

How does move direction work never used it before

#

wait nvm I got it

clever glacier
#

but first check it with theRootPartOfTheEnemy:CanSetNetworkOwnerShip()

#

i think the default networkownership is decided by the server

#

keep in mind if a player has NetworkOwnerShip on something, that player will be able to exploit to send it somewhere else (with cheats ofc)