0 votes

So I want my enemies to react when a player is near, either change animation, attack etc. With multiple enemies active at the same time, I'm wondering what's more efficient:

  1. In each enemy's code find player node and calculate distance every frame or
  2. Add an area to each enemy and use the on area entered signal/function or
  3. Some other way?

I'd just like to know what's more efficient in Godot and when does it start to matter, as in how many objects like this would there have to be in the scene for it to start significantly affecting performance.

in Engine by (35 points)

The Area nodes could be used to detect the player, and have the enemies react to the player's movements. The enemies could also have field of views which can detect the player. There's an example of this in the Vector math article on the dot product.

1 Answer

0 votes
Best answer

2) is probably easier and the recommended way. Shouldn't affect your performance too much, i put down 1000 objects to test it and the fps didn't even drop from 60.

by (256 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories