Discuss Scratch

invalidaccess
Scratcher
100+ posts

CHECKING OFF SCREEN PROJECTILE COLLISIONS

i like making scrolling games however ever since my first scrolling project i havent been able to figure out how to check for off screen collisions
for instance there's an enemy far away and you're not able to see it cus it's outside of the screen
so how do you know if your projectile touched the enemy or not
Cool_Dude2022
Scratcher
500+ posts

CHECKING OFF SCREEN PROJECTILE COLLISIONS

invalidaccess wrote:

i like making scrolling games however ever since my first scrolling project i havent been able to figure out how to check for off screen collisions
for instance there's an enemy far away and you're not able to see it cus it's outside of the screen
so how do you know if your projectile touched the enemy or not

Record where the enemy would be in a list and then check if the projectile would collide with that enemy.
invalidaccess
Scratcher
100+ posts

CHECKING OFF SCREEN PROJECTILE COLLISIONS

since enemies are not little dots you cant check a collision with only enemy positions
yes you can check if projectile is on a spesific point but its just a point not an enemy

at least thats what i thought
not_electric_ajax
Scratcher
92 posts

CHECKING OFF SCREEN PROJECTILE COLLISIONS

You can calculate whether the projectile is within a certain distance of the enemy's position, the distance being the enemy's size. Rectangular enemies are simple x-y lookups while spherical enemies need some more complex math (which I don't know how to do).
tank401
Scratcher
100+ posts

CHECKING OFF SCREEN PROJECTILE COLLISIONS

You can set their positions so they are in the screen and then check if they collide with a no screen refresh block, then put them back
sCrAtCh_139508
Scratcher
100+ posts

CHECKING OFF SCREEN PROJECTILE COLLISIONS

definegotopositionxysetcostocostumenameswitchcostumetoliterally nothingsetsizetojoinInfinityswitchcostumetogiant 480x360 rectanglegotox:xy:ysetsizeto100switchcostumetocos
tank401
Scratcher
100+ posts

CHECKING OFF SCREEN PROJECTILE COLLISIONS

I don't think this would work because it doesn't collide with it.?
MineTurte
Scratcher
1000+ posts

CHECKING OFF SCREEN PROJECTILE COLLISIONS

invalidaccess wrote:

i like making scrolling games however ever since my first scrolling project i havent been able to figure out how to check for off screen collisions
for instance there's an enemy far away and you're not able to see it cus it's outside of the screen
so how do you know if your projectile touched the enemy or not
You would need to do some math such as the math required for pen collisions. Not actual collisions, mathematically determined collisions.
invalidaccess
Scratcher
100+ posts

CHECKING OFF SCREEN PROJECTILE COLLISIONS

Nat101David wrote:

Watch this: https://www.youtube.com/watch?v=dQw4w9WgXcQ
BRUH
tank401
Scratcher
100+ posts

CHECKING OFF SCREEN PROJECTILE COLLISIONS

Usually with this stuff you don't need collisions off screen
ItBeJC
Scratcher
1000+ posts

CHECKING OFF SCREEN PROJECTILE COLLISIONS

invalidaccess wrote:

Nat101David wrote:

Watch this: https://www.youtube.com/watch?v=dQw4w9WgXcQ
BRUH
Yep I fell for it too .-.

But on a more on topic note-
It does depend on the shape of the enemy and how accurate you want collisions to be. So as stated before, let's say you have a square/rectangle for an enemy. This is easy because the area is straight forward, and there's no curves or anything. But with an enemy that's, let's just say, a circle…

Think about it this way: If you were to create a sprite, then you could create two costumes: One where the costume is a square and one where it's a circle. Assuming that the costumes are the same size, try to think about putting the circle on top of the square. If you did everything right, you should see that the circle doesn't cover up the full square. What that basically means is that if you have a square or rectangle sprite as the enemy, you can simply use the width & height to determine if the bullet touched it, and the calculation would be simple. But if you had pretty much anything BUT a square/rectangle, such as a circle, you'd have to use some complex math (idk how but u could probably find some on the web)

That's where the part where I said it depends on the accuracy you want comes in. Go back to the sprite where you put the circle on top of the square. If you don't care how accurate the game is, you could say that for any circular enemy, if a bullet touches anywhere on the square that circle is on top of, that enemy has been hit by a bullet. This is what I've done in the past, and I can show you how to do it in code if you'd like. But if you want the collisions to be more accurate, you'd have to find out how to determine whether or not an area of space is intersecting with another area of space that happens to be a circle, which I still cannot figure out.

TLDR: I can give u simple collisions that are not very accurate if the enemy is not a square/rectangle, or you can try to figure out the complex math for circle collisions. (Which idk how to do)
invalidaccess
Scratcher
100+ posts

CHECKING OFF SCREEN PROJECTILE COLLISIONS

ItBeJC wrote:

invalidaccess wrote:

Nat101David wrote:

Watch this: https://www.youtube.com/watch?v=dQw4w9WgXcQ
BRUH
Yep I fell for it too .-.

But on a more on topic note-
It does depend on the shape of the enemy and how accurate you want collisions to be. So as stated before, let's say you have a square/rectangle for an enemy. This is easy because the area is straight forward, and there's no curves or anything. But with an enemy that's, let's just say, a circle…

Think about it this way: If you were to create a sprite, then you could create two costumes: One where the costume is a square and one where it's a circle. Assuming that the costumes are the same size, try to think about putting the circle on top of the square. If you did everything right, you should see that the circle doesn't cover up the full square. What that basically means is that if you have a square or rectangle sprite as the enemy, you can simply use the width & height to determine if the bullet touched it, and the calculation would be simple. But if you had pretty much anything BUT a square/rectangle, such as a circle, you'd have to use some complex math (idk how but u could probably find some on the web)

That's where the part where I said it depends on the accuracy you want comes in. Go back to the sprite where you put the circle on top of the square. If you don't care how accurate the game is, you could say that for any circular enemy, if a bullet touches anywhere on the square that circle is on top of, that enemy has been hit by a bullet. This is what I've done in the past, and I can show you how to do it in code if you'd like. But if you want the collisions to be more accurate, you'd have to find out how to determine whether or not an area of space is intersecting with another area of space that happens to be a circle, which I still cannot figure out.

TLDR: I can give u simple collisions that are not very accurate if the enemy is not a square/rectangle, or you can try to figure out the complex math for circle collisions. (Which idk how to do)
well i dont care if its perfectly accurate or nah
could you show me your way

Powered by DjangoBB