#enemy knocks back forever when thrust is different than 1

1 messages · Page 1 of 1 (latest)

hot whale
winter linden
#

With every number other than 1? Even 1,1? or 1,05?

hot whale
#

those numbers doesnt do it thanks but why?

winter linden
#

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

hot whale
#

I dont understand it sometimes goes forever sometimes not

winter linden
#

Weird. Maybe it's colliding multiple times sometimes. So it hits the target with the knockback many times and they fly off like rockets.

tropic lion
#

You gotta do some debugging

#

Put logs in your functions, see if OnTriggerEnter is called when you don't expect it to

#

Etc.

winter linden
#

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.

tropic lion
#

@hot whale So is this script attached to the player?

hot whale
#

I think its about rigidbody not turning back to kinematic

hot whale
tropic lion
#

Ok, sounds reasonable.

#

Start debugging, I think there might be some overlapping coroutines or something

hot whale
#

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

tropic lion
#

Yep

hot whale
#

I must put if (enemy != null )

#

but where

tropic lion
#

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

tropic lion
#

if(enemy == null) yield break;