I implemented a simple AABB vs Sphere collision using this method from gamedev. It works fine when the sphere collides with the box from all sides.
The problem is that the sphere will not slip of the edge of the box. Meaning when the sphere falling in -y direction collides on the edge of the box, it will just go in +y direction again. See the picture below (taken after collision).
I think the problem is that the contactnormal is in this case always [0, 1, 0]. How do I achieve a more realistic behavior? For vector calculations I am using glMatrix.
var delta = vec3.create();
vec3.subtract(delta, centerRelSphereAABB, closestPoint);
distance = vec3.length(delta);
if(distance < C.radius){
penetrationDepth = C.radius - distance;
contactNormal = vec3.create();
vec3.subtract(contactNormal, delta, A.centerOfMass);
vec3.normalize(contactNormal, delta);
//contact point
contactPoint = vec3.create();
vec3.scale(contactPoint, contactNormal, C.radius - penetrationDepth);
vec3.subtract(contactPoint, model_1.centerOfMass, contactPoint);
}
The data is then forwarded to my collision response.
[attachment=23468:Clipboard02.jpg]