Enemy can recognize player, collision, lags

I have sometimes some lags, with recognizing “The Player”… I made a hitbox, its a square, If the player colide with it, the enemy is “recognize” it and “shoot”. I read that timer could help reducing the performance… Some one who can explain it? Or see a an other problem there…? Or have any advice! Thanks! …I have also an other question… I have for example 3 enemies… i made every event for them seperated, also its nearly the same… I found out , i there is away, to make diffrent instances of an object. Whould that reduce the performance too? and how can make that.

greetings thanks for your time!

1 Like

actionAfterRecognition

1 Like

Hello!
If your game is lagging, yes, you can try creating timer. I suggest you skip to second paragraph first though.
How timer would help?
Normally, the game will check if player is colliding with hitbox each frame per second. Your game probably runs at 60 frames per second, and then if, for example you have 5 hitboxes it will have to check if player is colliding with a hitbox 60 * 5 = 300 times the computer has to check if player is colliding with a hitbox, per second.
So with timer you can make it instead check 30 or 15 times per second, multiplied by number of hitboxes.

Although, I checked your EnemyShooter2 (recognize Player), it’s checking for too many conditions. Let’s think back to exactly how it should happen. Do you want to check if the enemy is not doing anything? Check if enemy is on one specific animation, or create object variable such as “targetingPlayer” to check if enemy already has a target.
The “Set animation of ShooterEnemy2 to “walk”” should also be under Trigger Once.

For the 3 nearly same enemies, use Object Groups.
image
For example, you can create an Object Group called “shootingEnemies” for enemies that shoot arrows, then click the 3 dots button, Edit Group, add the enemies from there. Then, change your events to use the Object Group names instead. In my case it’s EnemyChaser.

By the way, I have trouble reading/understanding the events. If my explanation did not solve, can you take screenshot with computer instead? Use the Windows program “snippingtool”.

1 Like

First of all, i am thankful for your help and your time! and I changed the Screenshots now!

I understand now, why i timer is useful! I’m not sure where i have to place it. And should I use a scene timer or object timer? :thinking: It would be better if I you a timer on every single collision in this game right?

And actually its the same enemy, only the number is different… Like shooterEnemy, shooterEnemy2, shooterEnemy3… I had to copy every single action, moving, health, death etc… And changing numbers. I found this group function. I had problems with it. For example. If enemygroup have a collision, change the direction. So the problem was, if one of 10 enemy has a collision, all 10, changing directions.
Same with losing health. I also had to every object/sprite separate. I read it is possible to using just one object/sprite, and using objects instances. But i couldn’t find how it works or what i have to do.

CollisonWithObjectTimer|690x121

I tried it… Is test 1 or test 2 correct? or only one them…or are both wrong?

Hi again!
Can you check your second post’s link? I can’t click it.

For enemy, object timer will be better; if you use scene timer, they will shoot/stop shooting at the same time, even the ones that did not see the player.

You can use sub-conditions to change only the relevant enemy, even though the enemies are using the same Object. For example, check if player is inside enemy hitbox, then create a sub event to check if enemy is colliding with the hitbox object, so only that enemy is selected (In my picture, only enemy closer than 600 pixels will chase the player).
Another example is give each enemy a “state” variable that can be “move”, “idle”, or “attack”, then create condition to check for these variables, and do the actions accordingly.
In other words, use conditions to make sure only the relevant objects are picked, instead of all of them.
I can’t find the article where it talks about this, but Finite State Machine concept might help with how you create your enemies…
http://wiki.compilgames.net/doku.php/gdevelop5/tutorials/finite_state_machine

CollisonWithObjectTimer_03


ofcurse i didnt test all “tests” at same time;)

thanks! i still not sure how to make the collision and objectimer… i understand the sense but i dont know how to use it… im sure if it is reducing the “counted Collisions per second” … at Test 3, it reduce every 0.2 second the 25 health while collision and not one time durant the collision.

Thanks for your Help so far! i will read it!