Okay. So I have a character who you can attack with. The attack is an explosion which is spawned on your character). I don’t want the character you play as to get hurt, but I want other characters of the same entity type to get hurt.
The explosion never hurts your player thanks to the code I wrote, and it does hurt other players, but only if the explosion doesn’t touch you at all! (I tried this by displacing the explosion). Oh, I also added (alreadyHitThis) to prevent the explosion from damaging every entity continuously.
The code I use is this:
Variable of importance:
public var creator:Player;
In the update:
var collide_p:Player = collide("player", x, y) as Player;
if (collide_p && collide_p.player != creator && collide_p != alreadyHitThis)
{
collide_p.takeDamage(damage, creator);
alreadyHitThis= collide_p;
}
The player who spawns the explosion sets itself as the creator of the explosion.
Now, my theory is that if both the explosion hits you and your enemy, collide_p does in fact = player, which prevents the function from running… But I literally have no idea how to fix this logically…