Problems with collision response

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Jan 17 17:16:12 EST 2010


On Sun, 17 Jan 2010 06:14:59 -0800, Joabos wrote:

> I'm doing a project, and I need to insert collision detection and
> response on it. Here's the code. What am I doing wrong?
> 
> 
>    #Update all sprites, map
>         self.player.update(dt)
>         
>         #Collide other sprites
>         collisions = rabbyt.collisions.aabb_collide_single(self.player,
> self.spriteList)
>         
>         for col in collisions:
>             pass

Why are you looping over the collisions but do nothing?


[...]
>        if len(collisions) > 0:
>             #Collide the sprite with the bounding line pass

You have turned a great chunk of code into a string with triple quotes. 
That essentially is equivalent to commenting it out: it will not be 
executed. Then you did it again to a second chunk of code.

Removing all the code that doesn't do anything, you have FIVE lines left:


self.player.update(dt)
collisions = rabbyt.collisions.aabb_collide_single(self.player,
  self.spriteList)
collisions = rabbyt.collisions.aabb_collide_single(self.player,
  self.map_manager.map_sprites())
for tile in collisions:
    self.player.collide(tile)


Notice that you generate collisions between the player and the sprite, do 
absolutely nothing with it, and immediately replace it with collisions 
between the player and the map.

Since you reported that there are no collisions between the player and 
the map, you need to check these three things:


(1) does player.collide actually do anything?

(2) does map_manager.map_sprites return the map sprites you expect?

(3) does rabbyt.collisions.aabb_collide_single detect the collisions?




-- 
Steven



More information about the Python-list mailing list