match mbg collision callback code and add deadzone to touch camera

This commit is contained in:
RandomityGuy 2023-09-22 23:17:56 +05:30
parent 914418cfa7
commit 180a29de75
2 changed files with 21 additions and 18 deletions

View file

@ -1553,6 +1553,8 @@ class Marble extends GameObject {
var passedTime = timeState.currentAttemptTime; var passedTime = timeState.currentAttemptTime;
var oldPos = this.getAbsPos().getPosition().clone();
if (this.controllable) { if (this.controllable) {
for (interior in pathedInteriors) { for (interior in pathedInteriors) {
// interior.pushTickState(); // interior.pushTickState();
@ -1712,13 +1714,6 @@ class Marble extends GameObject {
} }
} }
if (this.controllable && this.prevPos != null) {
var tempTimeState = timeState.clone();
tempState.currentAttemptTime = passedTime;
tempState.dt = timeStep;
this.level.callCollisionHandlers(cast this, tempTimeState, pos, newPos, rot, quat);
}
if (contacts.length != 0) if (contacts.length != 0)
contactTime += timeStep; contactTime += timeStep;
@ -1745,6 +1740,14 @@ class Marble extends GameObject {
} }
this.queuedContacts = []; this.queuedContacts = [];
var newPos = this.getAbsPos().getPosition().clone();
if (this.controllable && this.prevPos != null) {
var tempTimeState = timeState.clone();
tempTimeState.currentAttemptTime = passedTime;
this.level.callCollisionHandlers(cast this, tempTimeState, oldPos, newPos);
}
this.updateRollSound(timeState, contactTime / timeState.dt, this._slipAmount); this.updateRollSound(timeState, contactTime / timeState.dt, this._slipAmount);
} }

View file

@ -1395,21 +1395,21 @@ class MarbleWorld extends Scheduler {
this.playGui.formatGemCounter(this.gemCount, this.totalGems); this.playGui.formatGemCounter(this.gemCount, this.totalGems);
} }
public function callCollisionHandlers(marble:Marble, timeState:TimeState, start:Vector, end:Vector, startQuat:Quat, endQuat:Quat) { public function callCollisionHandlers(marble:Marble, timeState:TimeState, start:Vector, end:Vector) {
var expansion = marble._radius + 0.2; var expansion = marble._radius + 0.2;
var minP = new Vector(Math.min(start.x, end.x) - expansion, Math.min(start.y, end.y) - expansion, Math.min(start.z, end.z) - expansion); var minP = new Vector(Math.min(start.x, end.x) - expansion, Math.min(start.y, end.y) - expansion, Math.min(start.z, end.z) - expansion);
var maxP = new Vector(Math.max(start.x, end.x) + expansion, Math.max(start.y, end.y) + expansion, Math.max(start.z, end.z) + expansion); var maxP = new Vector(Math.max(start.x, end.x) + expansion, Math.max(start.y, end.y) + expansion, Math.max(start.z, end.z) + expansion);
var box = Bounds.fromPoints(minP.toPoint(), maxP.toPoint()); var box = Bounds.fromPoints(minP.toPoint(), maxP.toPoint());
var marbleHitbox = new Bounds(); // var marbleHitbox = new Bounds();
marbleHitbox.addSpherePos(0, 0, 0, marble._radius); // marbleHitbox.addSpherePos(0, 0, 0, marble._radius);
marbleHitbox.transform(startQuat.toMatrix()); // marbleHitbox.transform(startQuat.toMatrix());
marbleHitbox.transform(endQuat.toMatrix()); // marbleHitbox.transform(endQuat.toMatrix());
marbleHitbox.offset(end.x, end.y, end.z); // marbleHitbox.offset(end.x, end.y, end.z);
// spherebounds.addSpherePos(gjkCapsule.p2.x, gjkCapsule.p2.y, gjkCapsule.p2.z, gjkCapsule.radius); // spherebounds.addSpherePos(gjkCapsule.p2.x, gjkCapsule.p2.y, gjkCapsule.p2.z, gjkCapsule.radius);
// var contacts = this.collisionWorld.radiusSearch(marble.getAbsPos().getPosition(), marble._radius); var contacts = this.collisionWorld.boundingSearch(box);
var contacts = marble.contactEntities; // var contacts = marble.contactEntities;
var inside = []; var inside = [];
for (contact in contacts) { for (contact in contacts) {
@ -1417,7 +1417,7 @@ class MarbleWorld extends Scheduler {
if (contact.go is DtsObject) { if (contact.go is DtsObject) {
var shape:DtsObject = cast contact.go; var shape:DtsObject = cast contact.go;
if (contact.boundingBox.collide(marbleHitbox)) { if (contact.boundingBox.collide(box)) {
shape.onMarbleInside(timeState); shape.onMarbleInside(timeState);
if (!this.shapeOrTriggerInside.contains(contact.go)) { if (!this.shapeOrTriggerInside.contains(contact.go)) {
this.shapeOrTriggerInside.push(contact.go); this.shapeOrTriggerInside.push(contact.go);
@ -1430,7 +1430,7 @@ class MarbleWorld extends Scheduler {
var trigger:Trigger = cast contact.go; var trigger:Trigger = cast contact.go;
var triggeraabb = trigger.collider.boundingBox; var triggeraabb = trigger.collider.boundingBox;
if (triggeraabb.collide(marbleHitbox)) { if (triggeraabb.collide(box)) {
trigger.onMarbleInside(timeState); trigger.onMarbleInside(timeState);
if (!this.shapeOrTriggerInside.contains(contact.go)) { if (!this.shapeOrTriggerInside.contains(contact.go)) {
this.shapeOrTriggerInside.push(contact.go); this.shapeOrTriggerInside.push(contact.go);
@ -1450,7 +1450,7 @@ class MarbleWorld extends Scheduler {
} }
if (this.finishTime == null) { if (this.finishTime == null) {
if (marbleHitbox.collide(this.endPad.finishBounds)) { if (box.collide(this.endPad.finishBounds)) {
var padUp = this.endPad.getAbsPos().up(); var padUp = this.endPad.getAbsPos().up();
padUp = padUp.multiply(10); padUp = padUp.multiply(10);