Enemy kicks me through massive wall

Hi there,

this is the problem:
If i jump on the enemy, it will die. works.
But if the enemy touches me, my player gets kicked off. works.
But if there is a massive wall, i fly through it and the game is not playable anymore.

The Code:

That’s what it looks like:

Try using force not a tween.
Apply force to player on x and y

1 Like

Made it. Nothing happens. If the Player is in collision, he will jump, no force is activated. :frowning:

Yes, the problem was in the tween. Position (x and y) tweens will move you to the position without caring whether you should or should not be able to be in it (Like in a wall.)

First of all, your y-axis is reversed. To make Gunnar go up, you need to add a negative force. Adding a positive force will push him down. But… It should still work.

After spending some time, I figured it out. “Forces” don’t work as I thought. They say “Move an object at some speed (pixels per second) on x-axis and some speed on y-axis”.
So, you have a force that’s 500 pixels per second over the time of a single frame, say, 1/60th of a second. Then that’s just about 9 pixels! You move Gunnar by 9 whole pixels instantly (because it happens in a single frame.) So how do we fix it? We make it so that the force lasts some time.

I’ve done so using a timer. Check it out:

Oh, and I noticed you switched to English for the picture. Thank you for that.


1 Like

Thank you!
Looks nice but perhaps i don’t see my mistake…
(btw, i just did 500 to x and y to see if anything happens :wink: )

I tried to copy your way, but if the player is now in collision, the forces don’t stop.

Danke Dir!

I tried it with the blinking…

The blinking starts correctly for 1.5 seconds.

So i thought:
when PlayerHitBox is NOT blinking, stop the forces.
Also did not work.

Of course, but we must take everything into account :slight_smile:

1.5 seconds is a long time. If you mean that the forces should stop after hitting a wall, you could just add an “or” condition…?
…if timer ouch > 1.5 seconds
…Gunnar is in collision with wall: Stop PlayerHitBox and delete timer “ouch”

If that’s no fix, I would check if your timer isn’t being reset over and over again with some text variable.

1 Like

I’m so thankful for your help,

if it’s easier on Discord - np…

Any idea why it works for you, but not for me?

Of course your idea works!

Was my dumb mistake.

There was a
“If Player is in collision with the enemy” above…

Had to bring it one to the left.

It works! Thank you so much!

The bounce effect is cool, but not this situation, i learned.

Can be closed!