Skip to content

Instantly share code, notes, and snippets.

@flushpot1125
Created October 3, 2020 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flushpot1125/8a59c7eb6b1b70ca3c0a060dbaffbdb5 to your computer and use it in GitHub Desktop.
Save flushpot1125/8a59c7eb6b1b70ca3c0a060dbaffbdb5 to your computer and use it in GitHub Desktop.
import { Mesh, PhysicsImpostor, Vector3 } from "@babylonjs/core";
export default class BallComponent 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.SphereImpostor, { mass: 1, friction: 0, restitution: 1 });
this.physicsImpostor.sleep();
}
/**
* Applies the start impulse. This is called on the game is started when the user presses
* the space key on the keyboard.
*/
public applyStartImpulse(): void {
this.physicsImpostor.wakeUp();
this.applyImpulse(new Vector3(45, 0, 45), this.getAbsolutePosition());
}
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment