BUG - Attackers attack and destroy new defender

When an attacker is attacking a defender and we place a new one behind it, it calls the `OnTriggerEnter2D’ which passes the new defender as the selected target. The attacker destroys the new defender and proceeds ahead without destroying the former defender.

Fox/Lizard.cs

void OnTriggerEnter2D(Collider2D collider){
		GameObject collidedGameObject = collider.gameObject;
		if (!collidedGameObject.GetComponent<Defender> ()) {
			return;
		}

		if (collidedGameObject.GetComponent<Stone> ()) {
			animatorObject.SetTrigger ("isJumpingTrigger");
		} else {
			animatorObject.SetBool ("isAttackingBool", true);
			attackerObject.Attack (collidedGameObject);
		}
	}

Attacker.cs

public void Attack(GameObject targetGameObject){
		currentTargetObject = targetGameObject;
	}

How to fix this?

Hi,

Nice spot!

Perhaps you could use a bool to indicate that the attacker is attacking, then check that in the OnCollisonEnter2D method before calling the Attack method, e.g. Only attack if we are not already attacking.

@Rick_Davidson - possibly something to correct in the remastered version?

Thought of it. For above scenario - It will kill the current defender and move on. But if we place a new defender on the same tile after the old one is killed, the attacker will just walk away.

To make it look good, you’d probably want to consider the attacker was in the square, I have seen issues also where you can place another defender in the same square as the attacker, just as the first defender is destroyed. The attacker will edge forward slightly but then attack the new defender - that makes sense, but what can happen is that they end up edging across effectively passed the defender. For example, a crock on the left of the tomb stone, but still attacking it?!

As the defenders are placed typically in the centre of each square, using the half-way position would probably be good enough in order to determine whether the attacker attacks the new defender that has been placed, or, just carries on walking - it may take a little experimentation, but could be useful.

Yeah half way position and shifting-resizing the collider will do. Wont solve everything but its ok to let them attack or walk away in few positions.
Thanks for the help.

You’re very welcome :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms