How to block player when hitting other sprite

Hi,
I’m helping teach arcade.makecode in a TEALS Intro class. There is an assignment that includes making an “item” (sprite?) “block” the player, so they cannot go through it. I don’t see how that is possible. The player is set to be controlled by the controller buttons. Looking around, it seems like maybe a tile map and or wall is required, but that has not been covered yet in the class. I am thinking it would be done with a on overlap and then set the velocity to 0 or the velocity relative to the controller to 0. All I can figure is to have the player jump to some location, but that’s not very good gameplay.

3 Likes

You could make it so when overlapping with the shield the overlapping sprite is knocked back. If the velocity is only slightly higher than the movement speed of the overlapping sprite then the knockback would be less and it work as “stopping” the sprite.
You could determine the velocity of the overlapping sprite and just reverse it. Or determine the direction it’s facing and choose a velocity based on that (this is probably more consistent than the first one as it doesn’t rely on the overlapping sprite moving)

maybe you could try making that when the player’s sprite touchs the blocker sprite it changes the player’s sprite X by N or -N (N is a ramdom number)

Thanks!

based on what you said I have this, which gets current velocity (x,y) and then turns the controller velocity factors to 0 and then reverses the velocity for 2 seconds, and then restores controller control. (If that makes sense). I am trying to include a picture of the code.

I think this is adequate.

2 Likes

Does it work well?

it’s pretty good. The sprite that bounces ends up hitting a wall and stopping, and then the player can start maneuvering it again.

2 Likes

you’re welcome.