I'm using box2d to implement collision detection for my game.
In most cases, any type of collision detection does something like "remove enemy" or things like that which is uniform regardless of the direction.
In my case, collision detection is used to prevent hero from passing through the wall. So, it's important to know from which direction he hit the wall, so I can properly update his position. My template code for now is :
if(!collided){
rabbit.position = ccp(rabbit.position.x + (pitch/4),rabbit.position.y + ((roll/4)*(-1)));
}
else if(abs(roll)>abs(pitch)){
rabbit.position = ccp(rabbit.position.x + (pitch/4) ,rabbit.position.y);
}
else if(abs(pitch)>abs(roll)){
rabbit.position = ccp(rabbit.position.x,rabbit.position.y + ((roll/4)*(-1)));
}
else{
rabbit.position = ccp(rabbit.position.x,rabbit.position.y);
}
Of course, this code has a LOT of problems, almost too many to be listed here.
So, is there any way, using Box2D, that we could tell the direction from which the "hero" hit the object?
Thanks in advance.