#enemy knocks back forever when thrust is different than 1
1 messages · Page 1 of 1 (latest)
With every number other than 1? Even 1,1? or 1,05?
those numbers doesnt do it thanks but why?
Maybe you just put a too big of a number. If the enemies have low mass/drag they might fly really far away even with 2 or 3f
I dont understand it sometimes goes forever sometimes not
Weird. Maybe it's colliding multiple times sometimes. So it hits the target with the knockback many times and they fly off like rockets.
You gotta do some debugging
Put logs in your functions, see if OnTriggerEnter is called when you don't expect it to
Etc.
Yeah Debug.Log is really useful with this stuff.
I suck at math, but I looked up stuff and didn't spot anything wrong with the formula at a glance.
@hot whale So is this script attached to the player?
I think its about rigidbody not turning back to kinematic
it is attached to attackarea which gets activated while I hold mouse button 0
Ok, sounds reasonable.
Start debugging, I think there might be some overlapping coroutines or something
It doesnt knock back forever now but get MissingReferenceException: The object of type 'Rigidbody2D' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object. this error
I know the reason
Yep
Its because your Attack area owns the coroutine. And the coroutine is still running even after you destroy the enemy
The correct way would be to have the enemy own the coroutine instead
Meaning, having the IEnumerator on a script on the enemy
So that when the enemy is destroyed, the coroutine dies with it
But yeah you could also just put a null check right after the yield return new WaitForSeconds() 🤷♂️
if(enemy == null) yield break;