Collision Problem

Subscribe to Collision Problem 4 posts

avatar for evan999333 evan999333 322 posts
Flag Post

In the swf located here: http://www.fastswf.com/J_HNsL8

I am encoutering a problem with my hitTestPoint collision code below.

var pp:Point = playerVar.localToGlobal(new Point(0,0));
// Collide With Top Side
while (levelVar.wall03.hitTestPoint(pp.x, pp.y + radius-1, true))
{
	playerVar.y--;
	levelVar.y++;
	pp = playerVar.localToGlobal(new Point(0,0));
}
// Collide With Bottom Side
while (levelVar.wall03.hitTestPoint(pp.x, pp.y - radius, true))
{
	playerVar.y++;
	levelVar.y--;
	pp = playerVar.localToGlobal(new Point(0,0));
}
// Collide With Right Side
while (levelVar.wall03.hitTestPoint(pp.x - radius+1, pp.y, true))
{
	playerVar.x++;
	levelVar.x--;
	pp = playerVar.localToGlobal(new Point(0,0));
}
// Collide With Left Side
	while (levelVar.wall03.hitTestPoint(pp.x + radius, pp.y, true))
	{
	playerVar.x--;
	levelVar.x++;
	pp = playerVar.localToGlobal(new Point(0,0));
}

The player is located inside the levelVar so what should happen is that when the player hits the wall it simply sends the player and the wall away from each other until they are no longer touching. In the swf you’ll notice this works fine for the top of the wall03 but for the other sides it jitters back and forth. Anyone know why this is happening or how to fix it?

Use the arrow keys or wasd to move
 
avatar for qwerberberber qwerberberber 508 posts
Flag Post

http://www.kongregate.com/forums/4-game-programming/topics/259954-aabb-sweep-test-tutorial

 
avatar for evan999333 evan999333 322 posts
Flag Post

This is not a tile based game and I am using non square bounding box’d (ex rectangles that are turned, triangles, circles.) shapes so that link is not really relevant to my problem. I am wondering why this hitTestPoint method is working for the top of the object but not the other side. I don’t know that link is relevant to my problem and if it is then could you explaine how it works with the kind of shapes I am talking about.

 
avatar for qwerberberber qwerberberber 508 posts
Flag Post

I didn’t tell you to apply my entire tile algorithm to it; You can simply run a sweep test against each of your bounding boxes and retrieve the collision times. This is the problem with people like us, we hate to read :3 Anyways, try using my method instead of hitTest it’s a good method.