Collider List Contains causing Double Hit

It looks like my Contains for the List of colliders isn’t executing to return after a collider has been hit already, causing double damage to be dealt on 1 swing
Here is the console output on 1 swing:

Here is the WeaponDamage Script

I can’t for the life of me figure out what is causing the list Contains not to recognize a duplicate collider and stop a double hit

It’s possible that you have two colliders on the sphere. This will register two distinct collisions. You can see in the console that 2 spheres have exited the trigger. Or perhaps you have this script on your weapon twice

The order of the existing logs would seem to indicate that the weapon is hitting two distinct colliders that are possibly overlapping. Let’s add an extra Debug in the OnTriggerEnter() method. Turn off Collapse in the Console to get each message in order:

Debug.Log($"Hit Collider {other} on {other.gameObject.name}");

Yeah it appears to be hitting the sphere twice. Just below oin the next line is a duplicate hit and reduces to 60 (and also the targeter which is an asset nested in the player?.. I thought “myCollider” should prevent that?

lol… I’m dumb :smiley: the script was on there twice

Thank y’all both!!!

1 Like

I’ve done that before. You can prevent that on future weapons by adding this Attribute above the Class declaration

[DisallowMultipleComponent]

This will prevent you from putting a second copy of the component on the GameObject.

1 Like

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

Privacy & Terms