Discuss Scratch

GrayDevScratch
Scratcher
17 posts

Off-Screen Collisions

I'm making a 2d top down scrolling shooter game, but the enemies just phase through walls when off-screen. I tried zooming out, detecting collisions, and then zooming back in but it was both too laggy and just didn't work as intended. Any help?

Also, the map is one sprite, not multiple different ones.

Last edited by GrayDevScratch (March 26, 2024 16:48:54)

ramenecho
Scratcher
100+ posts

Off-Screen Collisions

Ok, if you are using color detection it will just not detect, but im pretty sure the <touching sprite > block still works offscreen, you could use that if possible
Malicondi
Scratcher
1000+ posts

Off-Screen Collisions

ramenecho wrote:

Ok, if you are using color detection it will just not detect, but im pretty sure the <touching sprite > block still works offscreen, you could use that if possible
<touching> sensing blocks don't work offscreen. The only way to accurately detect offscreen collision is to use math, and depending on your game the math needed to do so would be different.
GrayDevScratch
Scratcher
17 posts

Off-Screen Collisions

ramenecho wrote:

Ok, if you are using color detection it will just not detect, but im pretty sure the <touching sprite > block still works offscreen, you could use that if possible

I am using the <touching> sensing block, and It doesn't work off screen at least when I've tried it, but thanks for trying to help! (:
GrayDevScratch
Scratcher
17 posts

Off-Screen Collisions

If anyone has any ideas if they don't even know if they will work please still share them with me, cause my creativity has gone down the drain
-Qlec-
Scratcher
100+ posts

Off-Screen Collisions

Edit: See post below

A more practical solution is splitting up your sprite into tiles and dynamically rendering them based on the camera x and y positions.

Last edited by -Qlec- (March 26, 2024 18:34:44)

Malicondi
Scratcher
1000+ posts

Off-Screen Collisions

-Qlec- wrote:

And you'd have to do this for each of your enemies and every sprite that goes off-screen, every time. This does not work infinitely (e.g. you can't go to (-100000, -100000) probably).
actually you can go offscreen to any coordinates, including coordinates in the billions trillions, and even infinity :) It's really simple, all you have to do is make a empty 0x0 sprite inside of the vector editor, and use this script:
define go to x:(x) y:(y)
switch costume to [0x0 sprite v]
set size to ((1) / (0))
go to x:(x) y:(y)
switch costume to [normal sprite v]
set size to (100) %

Last edited by Malicondi (March 26, 2024 18:18:53)

and_the_dark_side
Scratcher
11 posts

Off-Screen Collisions

I've got the same problem with my games. I've been looking for a way to fix it as well, and the only solution I can find is something too complicated and most likely won't work, or using math which will not work for my game.

Powered by DjangoBB