This topic is 2443 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

to start off, I'll post a function I got

 public function solveTile(tx:int, ty:int, tileW:int, tileH:int,limits:float4):Boolean { if (!velX && !velY) return false; var colx:Boolean, coly:Boolean; var minx:Number,maxx:Number; minx = limits._0; maxx = limits._1; var disX:Number = Math.max(Math.abs(tx - maxx), Math.abs(tx + tileW - minx)); if (disX < maxx - minx + tileW) colx = true; var miny:Number, maxy:Number; miny = limits._2; maxy = limits._3; var disY:Number = Math.max(Math.abs(ty - maxy), Math.abs(ty + tileH - miny)); if (disY < maxy - miny + tileH) coly = true; if (colx && coly) //engage in sweep testing! { var depthx:Number = maxx - tx; if (velX < 0) depthx = minx - tx - tileW; var depthy:Number = maxy - ty; if (velY < 0) depthy = miny - ty - tileH; var xtime:Number = depthx / velX; var ytime:Number = depthy / velY; var coltime:Number = Math.min(xtime, ytime); if (xtime < ytime) { //this.x -= velX * coltime; repos._0 = - velX * coltime; velX = 0; } else { //this.y -= velY * coltime; repos._1 = - velY * coltime; velY = 0; } return true; } return false; } 

here is one of the inputs, the other parems should be straightforward.

 var minx:Number, maxx:Number; var v:Vector.<Number> = new <Number>[left + x, right + x,left + lastX, right + lastX]; minx = v[3]; maxx = v[3]; var i:int = v.length; while (i--) { if (v < minx) minx = v; if (v > maxx) maxx = v; } v = new <Number>[up + y, down + y,up +lastY, down + lastY]; var miny:Number, maxy:Number; miny = v[3]; maxy = v[3]; i = 4; while (i--) { if (v < miny) miny = v; if (v > maxy) maxy = v; } var limits:float4 = new float4(minx, maxx, miny, maxy); 

this works perfectly and uses sweep tests. It's basically an AABB vs AABB algorithm.

However, when I try to collide several tiles at once, wierd jitters happen, and I don't know what to do. Given this function, can someone give me a broad phase function? I've tried to collide with all the tiles at once, and even implemented checking order like this article said:
http://www.flatredba...=Tile_Collision
[font="Lucida Grande"] [/font]
[font="Lucida Grande"][size="4"]Other than that, I got nothing, so I decided to come to game dev for help. Can someone give me a fairly detailed lesson on how to collide with several tiles?[/font]
[font="Lucida Grande"] [/font]
[font="Lucida Grande"][size="4"]It's written in AS3, but every programmer can read that.[/font]

##### Share on other sites
Ok, so no one has posted yet; I'm new to this community, can anyone tell me why this thread was not attractive?

##### Share on other sites
Be patient. It can take several days to get a response.

You could also explain more about the behaviour you're seeing and why its not what you expect.

##### Share on other sites
Because you've posted a huge amount of code, that tends to put people off because the readers essentially then have the debug it while reading it which is a lot like what most of us do in our day jobs, so it feels like doing more work...

It might be better in future to post the broad idea, along with diagrams so everyone can understand your problem much more easily.

Having looked at your code a little and your description, I can take a guess that the reason you get jitter is because you're modifying the positions of your tiles directly in your collision detection? So, after you've moved one tile, its no longer where the system thinks it is, and thus the other collisions are wrong...

Cheers, Paul.

• 10
• 17
• 9
• 13
• 41