mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-26 12:41:40 +00:00
Fix some internal edge collisions??
This commit is contained in:
parent
a97643baa7
commit
e1d2faa2b5
2 changed files with 28 additions and 15 deletions
|
|
@ -701,12 +701,13 @@ class Marble extends GameObject {
|
||||||
var intersectT = this.getIntersectionTime(timeStep, velocity);
|
var intersectT = this.getIntersectionTime(timeStep, velocity);
|
||||||
|
|
||||||
if (intersectT < timeStep) {
|
if (intersectT < timeStep) {
|
||||||
// intersectT *= 0.8; // We uh tick the shit to not actually at the contact time cause bruh
|
intersectT *= 0.8; // We uh tick the shit to not actually at the contact time cause bruh
|
||||||
// intersectT /= 2;
|
// intersectT /= 2;
|
||||||
var diff = timeStep - intersectT;
|
var diff = timeStep - intersectT;
|
||||||
this.velocity = this.velocity.sub(A.multiply(diff));
|
this.velocity = this.velocity.sub(A.multiply(diff));
|
||||||
this.omega = this.omega.sub(a.multiply(diff));
|
this.omega = this.omega.sub(a.multiply(diff));
|
||||||
timeStep = intersectT;
|
timeStep = intersectT;
|
||||||
|
trace('CCD at ${intersectT}');
|
||||||
}
|
}
|
||||||
|
|
||||||
piTime += timeStep;
|
piTime += timeStep;
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,9 @@ class CollisionEntity implements IOctreeObject {
|
||||||
for (obj in surfaces) {
|
for (obj in surfaces) {
|
||||||
var surface:CollisionSurface = cast obj;
|
var surface:CollisionSurface = cast obj;
|
||||||
|
|
||||||
|
var surfaceBestContact:CollisionInfo = null;
|
||||||
|
var bestDot:Float = Math.NEGATIVE_INFINITY;
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while (i < surface.indices.length) {
|
while (i < surface.indices.length) {
|
||||||
var v0 = surface.points[surface.indices[i]].transformed(tform);
|
var v0 = surface.points[surface.indices[i]].transformed(tform);
|
||||||
|
|
@ -117,32 +120,41 @@ class CollisionEntity implements IOctreeObject {
|
||||||
|
|
||||||
var res = Collision.IntersectTriangleSphere(v0, v, v2, surfacenormal, position, radius);
|
var res = Collision.IntersectTriangleSphere(v0, v, v2, surfacenormal, position, radius);
|
||||||
var closest = res.point;
|
var closest = res.point;
|
||||||
// closest = Collision.ClosestPtPointTriangle(position, radius, v0, v, v2, surface.normals[surface.indices[i]]);
|
// var closest = Collision.ClosestPtPointTriangle(position, radius, v0, v, v2, surfacenormal);
|
||||||
if (closest != null) {
|
if (closest != null) {
|
||||||
if (position.sub(closest).lengthSq() < radius * radius) {
|
if (position.sub(closest).lengthSq() <= radius * radius) {
|
||||||
var normal = res.normal;
|
var normal = res.normal;
|
||||||
|
|
||||||
if (position.sub(closest).dot(surfacenormal) > 0) {
|
if (position.sub(closest).dot(surfacenormal) > 0) {
|
||||||
normal.normalize();
|
normal.normalize();
|
||||||
|
|
||||||
var cinfo = new CollisionInfo();
|
// We find the normal that is closest to the surface normal, sort of fixes weird edge cases of when colliding with
|
||||||
cinfo.normal = normal; // surface.normals[surface.indices[i]];
|
var testDot = normal.dot(surfacenormal);
|
||||||
cinfo.point = closest;
|
if (testDot > bestDot) {
|
||||||
// cinfo.collider = this;
|
bestDot = testDot;
|
||||||
cinfo.velocity = this.velocity;
|
|
||||||
cinfo.contactDistance = closest.distance(position);
|
var cinfo = new CollisionInfo();
|
||||||
cinfo.otherObject = this.go;
|
cinfo.normal = normal; // surface.normals[surface.indices[i]];
|
||||||
// cinfo.penetration = radius - (position.sub(closest).dot(normal));
|
cinfo.point = closest;
|
||||||
cinfo.restitution = surface.restitution;
|
// cinfo.collider = this;
|
||||||
cinfo.force = surface.force;
|
cinfo.velocity = this.velocity;
|
||||||
cinfo.friction = surface.friction;
|
cinfo.contactDistance = closest.distance(position);
|
||||||
contacts.push(cinfo);
|
cinfo.otherObject = this.go;
|
||||||
|
// cinfo.penetration = radius - (position.sub(closest).dot(normal));
|
||||||
|
cinfo.restitution = surface.restitution;
|
||||||
|
cinfo.force = surface.force;
|
||||||
|
cinfo.friction = surface.friction;
|
||||||
|
surfaceBestContact = cinfo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i += 3;
|
i += 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (surfaceBestContact != null)
|
||||||
|
contacts.push(surfaceBestContact);
|
||||||
}
|
}
|
||||||
|
|
||||||
return contacts;
|
return contacts;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue