Advertisement

Collision Detection Problem with Scale,Rotate,Fast Object

Started by December 29, 2014 04:43 AM
5 comments, last by InferiorOlive 10 years, 1 month ago

Hi guys, I am doing a platform game.I followed this topic and decided to pick 'Tile Surround Method" for collision detection (http://www.raywenderlich.com/15230/how-to-make-a-platform-game-like-super-mario-brothers-part-1).But I got some problems with this method:

1.My main character can scale up and scale down based on time,even it can rotate.(at this point,I tried matrix transform to calculate the bounding box after every frame) so it means my size is not fixed and "tile surround method" seems not working right.

2.My main character is a cube (rectangle shape) which would collide with obstacle like rectangle,triangle.So for collision detection,I just used some basic check on it( Rectangle with Rectangle, Triangle and Rectangle).Specially, with triangle and rectangle case, I just find triangle's 3 vertices and calculate its 3 edges and check what if they collide with my main character(a rectangle).

3.I got some problems when I increase main character's move speed.In some case, my collision dectection was passed( I heard about broadphase check but still have no clue on it smile.png )

Hope you guys can suggest to me some techniques to research,or some better method.Thanks in advance.

  1. As you are checking collisions every time step, you should be able to approximate the continuously changing collision shape of your character with a succession of slightly different shapes. Of course, assumptions about axis-aligned rectangles, testing exactly 4 or 9 tiles because the character is as large as one tile, and so on are limited to simpler cases; implement tests for arbitrary convex polygons vs. the tile map.
  2. Not a question. Where do triangles come from? Do you have sloped or partially solid tiles?
  3. Sounds like tunneling due to large movements. You should be able to figure out how far the character has to move (e.g. in a vertical fall towards a platform) from each valid position (e.g. barely above the platform, the worst case) to reach an invalid position (e.g. legs through the platform and feet in the air below it) beyond the range of correct ones (e.g. with feet penetrating the platform interior, which collision response will correct to standing on the platform).
    From this maximum movement distance you can either limit velocities to ensure that, even in the worst case, these movements do not occur in a single frame or subdivide each update in a sufficient number of simulation steps.
    For example, if the platform is 30 cm thick the character can fall at most 30 cm for update (less, to have some safety margin); a fall at 12 m/s requires 40 physics timesteps per seconds (more, to have some safety margin), presumably 2 for each redraw at 30 fps, while good behaviour at 30 updates per second requires reducing fall velocity below 9 m/s.

Omae Wa Mou Shindeiru

Advertisement

Thanks for answering, LorenzoGatti

1.I tried some complicated ways to calculate the bounding box and recalculate the number of tiles surround the main character(its size is not fixed so sometimes,its size represent by 1 tile but sometimes maybe 3-4 tiles (scale up).would there be any simple way to achieve this result ?

2.In my game,triangle plays as an obstacle,main character would die if it hit triangle.In this section,I just wanna ask about triangle vs rectangle collision method.

3.Thanks for this,I'll try :)

btw, my game is something look likes geometry dash which has a cube running,players have to try to avoid hitting obstacles.It has a feature like "bad land" that main character can scale up and down its size.I'm thinking about using box2d for my case (I knew that "bad land" team used box2d for their game).is it necessary to use it or I only use some basic way like matrix transform,collision detection etc... Thanks

For rectangle and triangle collision detection,

I think you don't really need to calculate the edges. You can simply check whether or not any of the 3 vertices of the triangle is in the rectangle. If yes, then it's a collision.

This method is simpler and faster, which may also solve your problem no.3 maybe?

I think I should take my previous answer back...

That check is indeed quick but doesn't cover all possible collision cases, e.g. your triangle and rectangle can still collide when none of the triangle vertices are inside the rectangle.

Maybe it's only useful as a fast first-round check and if the test fails you then want to fallback to the normal line-line intersection test.

I think I should take my previous answer back...

That check is indeed quick but doesn't cover all possible collision cases, e.g. your triangle and rectangle can still collide when none of the triangle vertices are inside the rectangle.

Maybe it's only useful as a fast first-round check and if the test fails you then want to fallback to the normal line-line intersection test.

yay, I was stuck in your case once :)

Advertisement

If you have a rectangle, each of its four vertices should be equidistant from the center-point, right? So, in determining which tiles are adjacent to your character, could you generate a circle of radius equal to (or greater than) the distance from any of the box's four vertices to the center point and determine which tiles that circle collides with or is near? This would accommodate rotating the box about its center as well as scaling.Alternatively, this radius could be used to determine the width/height of a square of the appropriate size to contain your character at any rotation. Both of these larger shapes would only need to be recalculated as the character's size/scale changed.

As for the triangle question, have you considered using the separating-axis theorem to determine collision? I'm not sure if that's outside the scope of what you've already implemented or want to implement, it's just an idea.

Inspiration from my tea:

"Never wish life were easier. Wish that you were better" -Jim Rohn

soundcloud.com/herwrathmustbedragons

This topic is closed to new replies.

Advertisement