#cat game issue
1 messages · Page 1 of 1 (latest)
Give me a sec ill just post the original script in here from u
https://hatebin.com/vvijnqsmsa
and you said you've changed OnCollisionEnter2D to be this right?
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Upgrade") && !hasCollidedWithUpgrade)
{
maxHealth++;
currentHealth++;
Destroy(collision.gameObject);
hasCollidedWithUpgrade = true;
}
else if (collision.gameObject.CompareTag("Rat"))
{
Vector2 knockbackDirection = transform.position - collision.transform.position;
TakeDamage(1, knockbackDirection);
}
}
yesyes
Ill help u add some debugs, but try to understand the thought process behind it as well
well firstly i gotta fix this error im getting all of a sudden before i can move on to anything else
Ok first thing, the issue is the cat is instantly dying, no matter what.
Lets test if thats true because theres a few cases:
- The cat is just colliding multiple times and processing multiple damage
- There are multiple things tagged Rat
- There is another script affecting this
show your updated code
which one
oh thats a different script i see
yeah
show the one with the error
idk why its causing an issue now
your TakeDamage script needs an int, and vector 2
i fixed it, now lets see the cat dying issue
- the logs said it only took one damage
- there are not multiple things tagged Rat at once
- yeah thats possible
show me the logs u wrote
especially for 1
the logs will show that it took 1 damage yes, but how many times did it take 1 damage?
Its possible it collides, the cat bumps off a little and then with forward velocity collides again
so either thats just naturally happening because the cat or rat (or both) have velocity towards each other and collide twice in this
or there are 2 colliders on the rat (like a body and arm) and both are colliding at once
theres only 1 collider on the rat
the best bet would be implement an immunity phase regardless for your player. A lot of games do this, its called either immunity frames, invincibility frames, or "i frames". Like if the player gets hit, dont let them take damage for some time, maybe 0.1 seconds, maybe 1 second
any other solution like ensuring they dont collide twice will be really annoying to implement
oo okay lemme try
yep that did the trick, tysm
nice, just curious how did u implement it