What it says on the tin. I detect the collision with the SAT, and while I'm doing that I also calculate a projection vector and the normal of the surface the collision took place on. I project my object then out of the collision.
By the way - this isn't supposed to be physically correct. I am assuming only one movable object and a bunch of static ones right now (this is for an arkanoid clone).
To get the bounce, I then calculate a vector perpendicular (clockwise) to the normal vector -let's call the normal n, the perpendicular vector p, and the velocity vector v - and then calculate the new velocity vector v like this:
u[1] = -v.n
u[2] = v.p
I don't quite get the results I expected though:
if the normal is {-1,0}, {0,1} or {0,-1} u[1] is always positive. I am testing this with AABB's right now, that's why the normals are like that.
My code for the collision resolution is here:
1 2 3 4 5 6 7 8 9 10 11
|
Intersection in = this->boundingBox.intersectsWith(*it);
if(in.intersects)
{
this->boundingBox.move(in.projection);
Vector2D p = in.normal.getNormalCW();
float horizontalFactor = -Vector2D::dot(this->speed, in.normal);
float verticalFactor = Vector2D::dot(this->speed, p);
this->speed = Vector2D{horizontalFactor,
verticalFactor};
}
|
should anyone need it I can also upload my full project.
I hope someone can help me with this, to be honest my math skills aren't exactly up to shape right now and this is really driving me nuts.