Tips with making enemy detect&attack system

Hi, i wan’t to make a enemy system where a NPC moves to player, but i need to know how to optimize detecting, what can i use to make checks ect. better and not lag entire game, i came with one solution: making dungeon system to make enemies on separate places, but it’s not what i will do, any tips how to otpimize loop which checks where the player is?

2 Likes

Do you want the enemy to know where the player is at all times even behind walls?

1 Like

yea, i wan’t most efficent way i can make it

Why don’t you just get the player’s position

1 Like

bc when i’ll loop it , + if there more than 1 player , they have to detect one, i wan’t the most optimized way with loop or not to check 4 times a second

If you want the enemy to lock onto one then check the distance between the enemy and all the players then choose the shortest distance and make that player your target

yea, kindof, but i don’t know the most efficent way, i used while loop

I think looping is the best way but instead of while loops use renderstep.hartbeat so it checks depending on the users fps

yea? i thought heartbeat is laggy and it runs every something like 1/50 of sec soo it will lag if the enemy will check it on server

Renderstep repeats based on the users frame rate

1 Like

but if heartbeat is on server?

You could check on the client and send it to the sever

Oh sorry it’s not heartbeat but it’s runserivce.renderstep

2 Likes

it can be vulnerable to exploits, and it will be multiplayer game, i need the best solution to detect if player is in range or not

Hmm it’s a tricky on to get a lag free and exploit free game. You might need to go old school with hitboxes just one giant one

2 Likes

hmmm, do you think hitboxes are less laggy?

Yes since their is a function that only fires when something is in it or moves

2 Likes

Ok i came with solution:

  1. Player is in hitbox (i don’t need to enemy detect player in range greater than 100)
  2. function blocks until the player is death/leave the hitbox
  3. do something
  4. detect with bounding box if player is still in range every 1 sec
  5. if not, then stop

thank you for helping me, and if you asking, interval that will check if player is not inside box will be loop every 0.9 second with magnitude check

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.