0 votes

ahhhhhh i'm stuck.

First time encountering this.
I instance some enemies > when my projectile hit they do all sort of things :
- slow them down.
- apply damage
- apply damage over time
etc... All this works perfectly. it only affect the body the projectile has touched.

But. When i want to make a projectile that make the enemy walk back to it starting point with getsimplepath, ALL the enemies turn around instead of only the one i hit.

The process is the same for ALL the other effect projectile does. But this one is problematic...
Any idea why ? is there a work around it ?

Here is my code :
enemy.gd which i instance:

Header part :

var path : = PoolVector2Array() setget set_path

Rest :
var navsendback = getnode("/root/MAINMAP/Nav/")
var navsendbackposition = getnode("/root/MAINMAP/startposition")
var pathsendback = navsendback.getsimplepath(self.position, navsendback_position.position) # we calculate their new path if any.

    set_path(path_send_back)

so when ever i update the path... it affect ALL instanced enemies. not just this one...
Any idea why ? thanks guys !

asked May 23 in Projects by quizzcode (152 points)

if anyone read this.... i'm still stuck on this :/

The process is the same for ALL the other effect projectile does.

Except that all the other effects (judging from the examples you gave at least) do not change the enemies path, isn't it?

so when ever i update the path... it affect ALL instanced enemies.

Odd. From the code you provided it's neither obvious what happens when a projectile is colliding with an enemy nor what set_path does though. The portion of the script you posted looks fine. However, it would be a lot easier to read if you would take the time to format it properly: all lines of code need to be indented by at least 4 spaces or underscores will be treated as markdown-elements.

Consider providing an example project if you can.

How do you instance your enemies?

get_node("/root/MAINMAP/Nav/") doesn't need to end with a "/" I'm surprised that didn't cause an error.

get_node("/root/MAINMAP/Nav/") doesn't need to end with a "/" I'm surprised that didn't cause an error.

Good catch! It didn't cause an error, because it isn't one: while the slash in the end is not necessary, it won't break anything either. Actually, "/root//MAINMAP///NAV////" would work as well. Nevertheless that's not the issue here, as quizzcode's script works. The problem is that it apparently works for all instances, not just one.

Thank you so much for all your answer. Always appreciate it !

Ehhm so this is awkward.
I always post the solution to my question as soon as i find it in case someone is looking for similar problems.

But this time, I have no idea why... but it's working. And I have no clue what changed.
I did mess around with the script without paying too much attention yesterday as i was over it. And somehow it's working.

So... Thank you everyone regardless.
And if i can reproduce the error i will post the "change".

Appreciate your help.

Please log in or register to answer this question.

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.