Good afternoon, team!
I have two characters (one is the player, the other is an undead monstrosity that must be destroyed!!). Attached to the front of each character is a sphere collider of radius 1, offset by a z of 1. Each has “isTrigger” checked.
When an object enters the trigger (using OnTriggerEnter), I check to the see if the other (Collider other) is on a different team (assigned in a variable). If it is, then I want to make the object entering my collider “vulnerable”, which is just a bool at this point (so I’m setting that to true).
The problem is that if the Combat script that is checking for OnTriggerEnter is attached to both characters, BOTH are marked as vulnerable.
If approaching each other from the front, this is fine, because they should enter each other’s colliders at the same time. If one (say, the player) is approaching the other (the undead monstrosity) from the rear, however, only the undead monstrosity should be marked vulnerable.
Basically, since they are both using the same script, and both checking “OnTriggerEnter”, as soon as either enters the other, then they both count as entering.
It seems that if a trigger is entered, by either party, the “OnTriggerEnter” conditions are fulfilled, but I only want the script to fire if the character is entering another character’s sphere collider, and NOT if the character’s own sphere collider is not entered.
Any ideas? If you need more clarification, I can try to explain more clearly!
Here’s my script:
void OnTriggerEnter (Collider other)
{
if (other.gameObject.GetComponent () != null) {
CombatState myOtherCombatState = other.gameObject.GetComponent ();
string myOtherTeam = myOtherCombatState.myTeam;
if (myTeam != myOtherTeam) {
myOtherCombatState.isVulnerable = true;
}
}
}