Unexpected behaviour by Lizard Attacker

I am observing some odd behaviour in Lizard animation attack transition. And sometimes it doesnt trigger attack animation at all and crosses every defender in way. I tried to Debug.Log(collider.name) to get the gameObject with which Lizard collides but didn’t got any clue.

Help me out if you have got any idea. Thanks in advance.

1 Like

Hi,

Set the Sleeping Mode of the Lizard’s Rigidbody2D component to “Never Sleep”.

Did this fix it?

Thanks for replying @Nina . But the Lizard behaviour is not changed.

On close observation i have deduced that game is not able to manage the transition between the animations of lizard.
What is happening –

if two lizard attacker are on scene and one collides with the defender’s collider. Then game triggers the transition of other lizard. If the lizard is alone on screen than it stops.

I don’t have a clue what to do.

I thought that might happen due to lack in time to find the Attacker component (FindObjectOfType().Attack(targetObject)) and since they are clone of each other might result in triggering the Attack animation of other lizard. Because we are setting the bool from Attacker script while we could have done it from the same lizard script on lizard itself, So i called the
“GetComponent().SetBool(“IsAttacking”, true);” from Lizard script only. And it worked now all lizards are attacking at correct position.

But @Nina i am still getting that error marked above.

Did you use FindObjectOfType<Attacker>() in your code? If so, that’s definitely wrong for the reason you described. You want to access the component of the Lizard, not “some” component somewhere in the Hierarchy.

Regarding the error message, it doesn’t seem to refer to your code. Have you already tried to restart Unity? If so, which version of Unity do you use?

1 Like

Thanks a lot @Nina it was blunder i did. But you saved me.
But i learned that we could even use this property that might help in some other way. A way to randomize things like attack by enemy in fps games.
i am using 2019.3.10 version. I think it fine to use this version for this unity 2d course.

Yes, that version is absolutely fine. I asked because some students install buggy alpha or super old versions of Unity.

1 Like

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

Privacy & Terms