use the hitbox of the rotated marble hitbox

This commit is contained in:
RandomityGuy 2022-12-17 20:19:56 +05:30
parent dc21945869
commit c4234c3c63
4 changed files with 50 additions and 7 deletions

View file

@ -1517,11 +1517,12 @@ class Marble extends GameObject {
quat.multiply(quat, rot);
this.setRotationQuat(quat);
var totMatrix = quat.toMatrix();
totMatrix.setPosition(newPos);
this.setPosition(newPos.x, newPos.y, newPos.z);
var tform = this.collider.transform;
tform.setPosition(new Vector(newPos.x, newPos.y, newPos.z));
this.collider.setTransform(tform);
this.collider.setTransform(totMatrix);
this.collider.velocity = this.velocity;
if (this.heldPowerup != null && m.powerup && !this.level.outOfBounds) {
@ -1606,7 +1607,8 @@ class Marble extends GameObject {
var expectedOmega = this.level.replay.currentPlaybackFrame.marbleAngularVelocity.clone();
this.setPosition(expectedPos.x, expectedPos.y, expectedPos.z);
var tform = this.collider.transform;
var tform = this.level.replay.currentPlaybackFrame.marbleOrientation.toMatrix();
tform.setPosition(new Vector(expectedPos.x, expectedPos.y, expectedPos.z));
this.collider.setTransform(tform);
this.velocity = expectedVel;

View file

@ -1481,9 +1481,6 @@ class MarbleWorld extends Scheduler {
var contacts = marble.contactEntities;
var inside = [];
var contactsphere = new SphereCollisionEntity(marble);
contactsphere.velocity = new Vector();
for (contact in contacts) {
if (contact.go != marble) {
if (contact.go is DtsObject) {

View file

@ -1,5 +1,6 @@
package collision;
import src.MarbleGame;
import src.TimeState;
import h3d.Matrix;
import src.GameObject;
@ -12,6 +13,8 @@ import h3d.col.Bounds;
class BoxCollisionEntity extends CollisionEntity {
var bounds:Bounds;
var _dbgEntity:h3d.scene.Mesh;
public function new(bounds:Bounds, go:GameObject) {
super(go);
this.bounds = bounds;
@ -21,6 +24,24 @@ class BoxCollisionEntity extends CollisionEntity {
public override function generateBoundingBox() {
this.boundingBox = bounds.clone();
this.boundingBox.transform(this.transform);
// if (_dbgEntity == null) {
// var cube = new h3d.prim.Cube(this.boundingBox.xSize, this.boundingBox.ySize, this.boundingBox.zSize, true);
// cube.addNormals();
// cube.addUVs();
// _dbgEntity = new h3d.scene.Mesh(cube);
// _dbgEntity.material.mainPass.wireframe = true;
// _dbgEntity.setTransform(transform);
// MarbleGame.instance.scene.addChild(_dbgEntity);
// } else {
// _dbgEntity.setTransform(transform);
// }
}
public override function setTransform(transform:Matrix) {
super.setTransform(transform);
// if (_dbgEntity != null) {
// _dbgEntity.setTransform(transform);
// }
}
public override function rayCast(rayOrigin:Vector, rayDirection:Vector) {

View file

@ -1,16 +1,20 @@
package collision;
import h3d.Matrix;
import src.TimeState;
import src.Marble;
import h3d.col.Ray;
import h3d.Vector;
import h3d.col.Sphere;
import h3d.col.Bounds;
import src.MarbleGame;
class SphereCollisionEntity extends CollisionEntity {
public var radius:Float;
public var marble:Marble;
var _dbgEntity:h3d.scene.Mesh;
public function new(marble:Marble) {
super(cast marble);
this.marble = marble;
@ -24,6 +28,25 @@ class SphereCollisionEntity extends CollisionEntity {
var pos = transform.getPosition();
boundingBox.addSpherePos(pos.x, pos.y, pos.z, radius);
this.boundingBox = boundingBox;
// if (_dbgEntity == null) {
// var cube = new h3d.prim.Cube(this.boundingBox.xSize, this.boundingBox.ySize, this.boundingBox.zSize, true);
// cube.addNormals();
// cube.addUVs();
// _dbgEntity = new h3d.scene.Mesh(cube);
// _dbgEntity.material.mainPass.wireframe = true;
// _dbgEntity.setTransform(transform);
// MarbleGame.instance.scene.addChild(_dbgEntity);
// } else {
// _dbgEntity.setTransform(transform);
// }
}
public override function setTransform(transform:Matrix) {
super.setTransform(transform);
// if (_dbgEntity != null) {
// _dbgEntity.setTransform(transform);
// }
}
public override function rayCast(rayOrigin:Vector, rayDirection:Vector) {