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?
Collision in an infinite scroll 2D game
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 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.
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
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;
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
For broad phase i guess a grid is a good idea in most 2D games
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement