How to code a mind control spell

Godot Version 3


I am trying to code a specific function in my top down game (kind of like vampire survivors)
So far I have a function that will detect when an enemy is in range of my player collision.
I am a newbie to gdscript and don’t know where to go from here.

My goal is to be able to have the ability on countdown that when pressed, will turn all enemies (within the collision sphere around my character) against the other enemies spawning and will not attack my player. I have movement, menu, health, range spell, and everything else figure out but this is stumping me. If anybody can help me or at least point me in the right direction to some resources I would appreciate it.

Thanks in advance! :slight_smile:


this sounds like plant vs. zombies’ hypno shroom.

what i see is possible is to add a method changing enemy’s state when got hit by player’s mind control spell area. like if the enemy got hit, it changed to hypno state, for hypno state it specified in code it will target enemy instead of player (can be checking it from group)

1 Like

This kind of games are performance first so you’ll have to think well the design and limits of the feature to make it performant, the issues you’ll face are the same as in any other engine.

  • you can be surrounded by dozens of enemies affected by the skill, that affects any logic you do by insane amounts (needs to perform really well)
  • the enemies can be surrounded by many enemies, you’ll have to pick one to attack
  • the enemies can be isolated and enemies could be far away, how you’ll pick which to attack
  • how would the normal enemies react, if they need to face or ignore the attacker

I would limit the feature to some kind of OPTION weapons on shmups, make the enemies affected walk around the player and attack any other enemy in range.
Because if you need to find every enemy and check which one is closer, it will take ages to end if the screen is filled with enemies.

Another option is to limit how many enemies can be controlled, that could allow to make a detection shape cast every few frames to find someone to attack, still it can find nothing and you’ll have to keep casting bigger shapes, which is not a problem if you have a few enemies doing it.

Then if normal enemies need to face the attacker, it could be a problem, every enemy needs to know how to do it (like, be aware about the attacker, if it died, is not much but with hundreds of enemies, it adds up).
An option, controlled enemies are ignored by the rest but die after a few seconds.

Finally on how to attack, depending on how you’ve designed your game these enemies could be added to a Player group and/or Player mask to receive enemy attacks and avoid player’s attacks, their attacks should also change the mask to match the player.
All that mask management is cheap and since it is done on affected enemies it shouldn’t be much of a problem.

1 Like

Ahhhh that makes sense,


THanks so much for the in depth explanation. Luckily its for a game jam so I’m not too worried about making it very complex. But I appreciate the insight and this has helped me understand what I would need to do to implement it.


1 Like