Log In  

I've done collision detection with object/object and object/tiles. But what is a good way to detect object/shape?

I have a 8x8 player sprite. You can move it, etc. Across the screen is the bad guy and he's shooting at you. If a his bullet hits the player, the player dies.

I want to use circfill() as the enemy bullet rather than a sprite.

I would have the player's _update() cycle check for the collision but what exactly would I check for?

My first thought was to loop through each of the player's hitbox x/y pairs and an use pget() to see if that location has changed to the color of the enemy bullet. But that sounds very expensive to do on every tick.

Is there a better way? I feel like there probably is.

Thoughts and feedback are appreciated.

P#20721 2016-05-17 16:48 ( Edited 2016-05-17 23:01)

How about getting the distance between the bullet centre and the player centre and if it is less than both their radius added together then the bullet has hit?

P#20729 2016-05-17 17:25 ( Edited 2016-05-17 21:25)

the alternatives are imperfect but faster, similar to what happens in bullet hells:
1: use the circle thing pidfsh writes. The trick is to match square distance and the sum of the radiuses' squares, there's no need to extract square roots
2: want to cheat a bit? use manhattan distance and "manhattan radiuses", sum should be faster than multiplication
3: want to cheat a lot? use a square smaller than the sprite for each actor, see when the squares collide

if you have a lot of sprites you can make the whole thing even faster cleverly using quad-trees, or even just di-trees split in the direction bullets usually go

P#20733 2016-05-17 19:01 ( Edited 2016-05-17 23:01)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-18 21:36:24 | 0.006s | Q:10