This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Mesh, PhysicsImpostor } from "@babylonjs/core"; | |
export default class BlockComponent extends Mesh { | |
// ... | |
/** | |
* Called on the node is being initialized. | |
* This function is called immediatly after the constructor has been called. | |
*/ | |
public onInitialize(): void { | |
this.physicsImpostor = new PhysicsImpostor(this, PhysicsImpostor.BoxImpostor, { mass: 0, friction: 0, restitution: 1 }); | |
this.physicsImpostor.forceUpdate(); | |
} | |
/** | |
* Called on the scene starts. | |
*/ | |
public onStart(): void { | |
// Register event to know when the block collides with the ball. | |
let onPhysicsCollideFunc: () => void; | |
this.physicsImpostor.registerOnPhysicsCollide(this._ball.physicsImpostor, onPhysicsCollideFunc = () => { | |
this.physicsImpostor.unregisterOnPhysicsCollide(this._ball.physicsImpostor, onPhysicsCollideFunc); | |
this.physicsImpostor.dispose(); | |
this.setEnabled(false); | |
}); | |
} | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment