- #1
MTK
- 13
- 0
I implemented collisions with walls in my Java physics engine, complete with elasticity and friction, but I am not sure how to calculate the post-collision rotation. Maybe you can help?
Here is the wall collision method (if you can understand it) :
Here is the wall collision method (if you can understand it) :
Code:
public void processWallCollision(Vector normal) {
Vector wall = normal.rotate(Math.PI/2);
Vector normalProjection = velocity.projectOnto(normal);
Vector wallProjection = velocity.projectOnto(wall);
normalProjection = normalProjection.reverse();
normalProjection = normalProjection.scale(elasticity);
wallProjection = wallProjection.scale(1-friction);
velocity = normalProjection.add(wallProjection);
}