Problems with collision response

J

Joabos

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

#Collide with map
collisions = rabbyt.collisions.aabb_collide_single(self.player,
self.map_manager.map_sprites())

for tile in collisions:
#Create a bounding line of all the tiles
self.player.collide(tile)
if len(collisions) > 0:
#Collide the sprite with the bounding line
pass
"""
if self.player.bottom < tile.top and self.player.top > tile.top:
self.player.collide(tile.attributes['col_type'],
DIRECTION.DOWN, tile.top)
elif self.player.top > tile.bottom and self.player.bottom <
tile.bottom:
self.player.collide(tile.attributes['col_type'],
DIRECTION.UP, tile.bottom)
elif self.player.left < tile.right and self.player.right >
tile.right:
self.player.collide(tile.attributes['col_type'],
DIRECTION.LEFT, tile.right)
elif self.player.right > tile.left and self.player.left <
tile.left:
self.player.collide(tile.attributes['col_type'],
DIRECTION.RIGHT, tile.left)
"""

#Collide with boundaries
"""if self.player.right > self.window_width:
self.player.collide(COL_TYPE.WALL, DIRECTION.RIGHT,
self.window_width)
elif self.player.left < 0:
self.player.collide(COL_TYPE.WALL, DIRECTION.LEFT, 0)

if self.player.bottom < 0:
self.player.collide(COL_TYPE.WALL, DIRECTION.DOWN, 0)
"""
 
D

Diez B. Roggisch

Am 17.01.10 15:14, schrieb Joabos:
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?

Not telling us what's happening, and what *should* happen, for starters.

What do you expect? The code you gave us isn't stand-alone, you don't
give any context of what libraries you use, nor what error you see, if any.

The inevitable link to read:

http://catb.org/~esr/faqs/smart-questions.html

Diez
 
D

Diez B. Roggisch

Am 17.01.10 15:14, schrieb Joabos:
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?

Not telling us what's happening, and what *should* happen, for starters.

What do you expect? The code you gave us isn't stand-alone, you don't
give any context of what libraries you use, nor what error you see, if any.

The inevitable link to read:

http://catb.org/~esr/faqs/smart-questions.html

Diez
 
J

Joabos

Diez said:
Am 17.01.10 15:14, schrieb Joabos:

Not telling us what's happening, and what *should* happen, for starters.

What do you expect? The code you gave us isn't stand-alone, you don't
give any context of what libraries you use, nor what error you see, if
any.

The inevitable link to read:

http://catb.org/~esr/faqs/smart-questions.html

Diez

Oh, sorry. Well, what's happenning is, whenever I boot the entire project,
there is *no* collision at all, when the player should stand on a tile. I
use Rabbyt and pyglet. There are no errors.
 
S

Steven D'Aprano

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?
 
J

John Nagle

Joabos said:
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?

Where to begin...

1. Most of your code will never be executed because it is inside
multiline triple-quoted strings.

2. Your approach to collision response probably won't handle multiple
simultaneous collisions.

3. You're expecting others to debug your code.

John Nagle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,177
Messages
2,570,953
Members
47,507
Latest member
codeguru31

Latest Threads

Top