Why does my collision happen twice?

In implementing the damage from the zucchini, I found that the collision seems to get reported twice. So that when I had the health set to 100 and the damage being done was 50 it was killing the lizard on the first hit. Doubling the health to 200 it now takes two hits to kill it.

I put in debug output to verify this. Each lizard is numbered, by adding a number to the end of the name, so you can see which one is being reported as being hit.

I asked this in the Facebook group, but I don’t have two colliders on anything, which was one suggestion.

Here is my Debug.Log() output as a screen capture:
image

Hi,

Check your game object. Are there 2 scripts attached? Log the name and the instance id (GetInstanceID()) of the current game object as well as the name and instance id of the colliding game objects into your console to figure out more. And Time.frameCount could also be interesting to see whether the collision events are getting triggered in the same frame.

Nina,

Thanks for the suggestion. It turns out I had two events at the exact same time that called the Fire() method. It was very hard to see when you look at the animation, but what should have been a single bar was shown as blue with a little bit of white on the top to show that there were two marks there.

By pausing it during the play you could see two Zucchini object in the hierarchy. By selecting one and moving it to the right you could see the other one that was at the same position. Visually they matched each other frame-by-frame, so visually you could not see it.

Good job on analysing the problem further. How did you notice that you had two events at the same time? :slight_smile:


See also:

It was pretty clear when I had a Debug.Log() output showing two collisions at the same time, since new zucchinis only fire a few seconds apart it was pretty clear that two events were happening. I was thinking originally it was the type of collider setting, so I changed it to continuous, but that had no effect and neither did changing any other settings, so that sort of eliminated the collider being the problem.

1 Like

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

Privacy & Terms