Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.