• Create Account

Banner advertising on our site currently available from just \$5!

# Collision in an infinite scroll 2D game

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1Lama43  Members   -  Reputation: 136

Like
0Likes
Like

Posted 18 August 2012 - 08:32 AM

Hello, i am currently developing a game in which the player runs indefinitely and can jump to fairly great heights (but not infinite, obviously). My problem is that i am lost at how to handle the whole collision thingy.

In my design any object can have any rotation, as such i need to have a sort of collision box that can rotate along with the objects. I've tried to develop something but my knowledge of physics is very limited (i'm still pretty young and school didn't teach me a lot yet) and here i am asking for help.

So, i have a problem with the narrow phase detection, but i'm not even sure on what to do in the broad phase. I tried to implement a recycling cell system but i've got the feeling it's going to be very cumbersome and slow, and since i'm developing on Android i need the maximum efficiency.

My question is, how can i handle rotated collision boxes? And what system should i use to partition my world?

### #2David.M  Members   -  Reputation: 731

Like
0Likes
Like

Posted 18 August 2012 - 10:19 AM

I would use two triangles that compose a box for collision detection. You can just apply a rotation matrix to rotate the vertices of the triangles when your object rotates.

### #3Lama43  Members   -  Reputation: 136

Like
0Likes
Like

Posted 18 August 2012 - 01:47 PM

I would use two triangles that compose a box for collision detection. You can just apply a rotation matrix to rotate the vertices of the triangles when your object rotates.

I probably expressed it badly, but my problem is not how to make the box, but rather how to detect collision with other boxes.

### #4David.M  Members   -  Reputation: 731

Like
0Likes
Like

Posted 18 August 2012 - 03:38 PM

Oh, I see. I read "In my design any object can have any rotation, as such i need to have a sort of collision box that can rotate along with the objects. I've tried to develop something but my knowledge of physics is very limited" as asking how to implement a box that can rotate freely. I didn't see the "My problem is that i am lost at how to handle the whole collision thingy" above it.

If you're using rectangles you can use
Rectangle r1; //both rectangles are assigned to bounding boxes
Rectangle r2;
if(r1.lowerLeft.x < r2.lowerLeft.x + r2.width &&
r1.lowerLeft.x + r1.width > r2.lowerLeft.x &&
r1.lowerLeft.y < r2.lowerLeft.y + r2.height &&
r1.lowerLeft.y + r1.height > r2.lowerLeft.y)
return true;
else
return false;

### #5Inferiarum  Members   -  Reputation: 735

Like
1Likes
Like

Posted 18 August 2012 - 05:09 PM

for the narrow phase http://www.wildbunny.co.uk/blog/2011/04/20/collision-detection-for-dummies/ could be useful
For broad phase i guess a grid is a good idea in most 2D games

### #6Lama43  Members   -  Reputation: 136

Like
0Likes
Like

Posted 20 August 2012 - 10:34 AM

for the narrow phase http://www.wildbunny...on-for-dummies/ could be useful
For broad phase i guess a grid is a good idea in most 2D games

Thanks, that's exactly what i need.
@David.M: Thanks for replying too, but that's for common horizontal rectangles, and i need something more complex than that.

Edited by Lama43, 20 August 2012 - 10:36 AM.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS