I've been screwing around with this collision response far to long now. I thought i'd ask you guys for some guidance.
http://jsbin.com/qoyuciti/1 Edit link: http://jsbin.com/qoyuciti/1/edit?html (just know that you can't use the movement keys in jsbin edit mode (as far as i know))
This JSBin shows what i have at the moment. I can move around and when i hit the box i won't go trough and i glide of the box. There are two problems:
A quick explanation of my approach
User starts walking, as soon as i intersect with the box i start testing for intersects in a 180 degree cone in front of the sphere (the direction the user is heading). As soon as it finds an empty spot it will put the player there.
If anyone has a better approach please let me know. As i'm explaining my code it seems like this could go more efficient but let me know :)
Thanks in advance!
I've fixed the problem i was experiencing. Here's the code for anyone who needs it :)
var intersect = box.intersectsPoint(player.position);
if (intersect) {
var x = prevX,
z = prevZ,
slideSpeed = speed * 0.7;
for (var angle = 0; angle > -90; angle -= 1) {
x = prevX - Math.sin((direction - angle) * Math.PI / 180) * slideSpeed;
z = prevZ - Math.cos((direction - angle) * Math.PI / 180) * slideSpeed;
var intersect = box.intersectsPoint(new BABYLON.Vector3(x, player.position.y, z), true);
if (!intersect) {
break;
}
x = prevX - Math.sin((direction + angle) * Math.PI / 180) * slideSpeed;
z = prevZ - Math.cos((direction + angle) * Math.PI / 180) * slideSpeed;
var intersect = box.intersectsPoint(new BABYLON.Vector3(x, player.position.y, z), true);
if (!intersect) {
break;
}
}
player.position.x = x;
player.position.z = z;
}