newbie collision question

24 views
Skip to first unread message

Jonathan Hartley

unread,
Apr 4, 2011, 5:02:54 AM4/4/11
to Rabbyt
Hey all,

I'm just trying to figure the best way to detect collisions between my
game's few moving objects (perhaps best modelled as circular collision
areas) and some chunky walls, which obviously are long and relatively
thin.

Am I right in my understanding that even if I make my walls axis-
aligned rects, I still can't check for collisions amongst my circular
moving objects and my aabb walls? I have to choose between either
performing collision checks against a bunch of circles, OR against a
bunch of aabbs? Or have I misunderstood?

I understand that Rabbyt collision checks are a good first pass which
I can subsequently refine with my own more detailed checks against the
'potential collisions'.

Thanks for clarifications or suggestions.

Jonathan

tsturzl

unread,
Apr 4, 2011, 1:27:33 PM4/4/11
to Rabbyt
For the sake of not using an immense amount of CPU use
collide_single(..) or aadd_collide_single(..)

I'm currently working on a game in pygame, and the collision system
consists of keeping track of which direction the character is moving.
If the character is moving left and a collision occurs, that means he
must have collided with an object, therefore I halt his movement. Same
thing if you're implementing gravity, keep iterating on the Y axis
till the character collides with the flood sprite.

A good method for using in Rabbyt would be to make a list of all
collidable objects(walls, rocks, etc.), and just enclosing the floor
sprite object in a list right before collision checking. So something
like this:
obj=[] #All collidable objects on map
floor=rabbyt.sprite()
avatar=rabbyt.sprite()
..
if collide_single(avatar,obj): #this means, if there is any collision
#Stop player movement.
if not collide_single(avatar,[floor]): #If you're not colliding with
the floor
avatar.y+=5 #you fall by 5 sprites till the statement is false.


I hope that helps, if you have any other questions just reply.

Jonathan Hartley

unread,
Apr 4, 2011, 1:52:57 PM4/4/11
to Rabbyt
Thanks Tzturzi, performance-wise it sounds like you're right that I
need to not check whether immobile objects have collided with each
other. Good call, and much appreciated.

In terms of the collision shapes though, my original question still
stands.

tsturzl

unread,
Apr 4, 2011, 10:37:04 PM4/4/11
to Rabbyt
Well Rabbyt doesn't really support collision with certain shapes, at
least from what I know. If you have an image with a triangle in it,
the image itself is still a rectangle, and so is the colliding space.
Rabbyt seems to do collisions strictly from image to image.
Alternatively you could use another system for collisions, I had the
same issue with Rabbyt in the past and used ODE to create collision
geoms and track collisions. However incorporating an entire physics
engine into your project just for collision detection would be kinda
overkill.

Right now I'm using pygame for my projects because of rabbyts lack of
a flexible collision system. My fix for odd shapes that require
collisions, is to map out points on the sprite that are collision
points, and I can programmaticly map out the entire boarding pixels of
the shape inside the image. So I basically construct a list of the
collidable points on the sprite and then I call rect.collidepoint(..)
in a for loop iterating through the list. This allows me to map out
the shape within the image, and ignore collisions with the empty/white
space in the image. I hope that makes sense, however I'm not sure if
is possible to implement something like that in rabbyt.

Jonathan Hartley

unread,
Apr 5, 2011, 4:23:14 AM4/5/11
to rab...@googlegroups.com
Hey,

Thanks for the response tsturzl!

Rabbyt does support collisions for either circles, or for AABBs. My
question is, can I mix the two? e.g. do collide_single(player, walls)
where the player is a circle, the walls are AABBs?

Many thanks!

Jonathan

--
Jonathan Hartley tar...@tartley.com http://tartley.com
Made of meat. +44 7737 062 225 twitter/skype: tartley


Matthew Marshall

unread,
Apr 5, 2011, 8:36:12 PM4/5/11
to rab...@googlegroups.com
No, rabbyt does not have a function to check for collisions between
bounding circles and bounding boxes. It's either one or the other.

So you had the right idea in the beginning: Use rabbyt.collisions as a
fast first pass before doing your more detailed collision checks.

Looks like there are some good solutions here:
http://stackoverflow.com/questions/401847/circle-rectangle-collision-detection-intersection

MWM

> --
> You received this message because you are subscribed to the Google Groups
> "Rabbyt" group.
> To post to this group, send email to rab...@googlegroups.com.
> To unsubscribe from this group, send email to
> rabbyt+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/rabbyt?hl=en.
>
>

Jonathan Hartley

unread,
Apr 6, 2011, 3:22:21 AM4/6/11
to rab...@googlegroups.com
Thanks for the response Matthew! I just wanted to check my understanding
was correct! You're da best.

Jonathan

Reply all
Reply to author
Forward
0 new messages