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, KeyboardEventTypes, Vector3, | |
AnimationGroup,PhysicsImpostor,PhysicsHelper | |
} from "@babylonjs/core"; | |
import { onKeyboardEvent, fromScene,fromChildren } from "../tools"; | |
import SceneManager from "./SceneManager"; | |
export default class character extends Mesh { | |
@fromChildren("Ball") | |
private _ball: Mesh; | |
public _scene:SceneManager; | |
private animForward : AnimationGroup; | |
private animMmaKick : AnimationGroup; | |
private animIdle : AnimationGroup; | |
private _pressedForwardKey : boolean; | |
private _pressedKickKey : boolean; | |
protected constructor() { } | |
public onInitialize(): void { | |
// ... | |
} | |
public onStart(): void { | |
this.animForward=this._scene.getAnimationGroupByName("RunningInPlace"); | |
this.animIdle = this._scene.getAnimationGroupByName("Idle"); | |
this.animMmaKick = this._scene.getAnimationGroupByName("MmaKick"); | |
this.animIdle.start(true,1.0,this.animIdle.from,this.animIdle.to, false); | |
} | |
public onUpdate(): void { | |
} | |
public onStop(): void { | |
// ... | |
} | |
@onKeyboardEvent([84], KeyboardEventTypes.KEYDOWN)//T | |
private _moveStraight():void{ | |
if ( this._pressedForwardKey == false){ | |
this.animIdle.stop(); | |
this._pressedForwardKey =true; | |
} | |
this.animForward.start(true, 1.0, this.animForward.from, this.animForward.to, false); | |
this.translate(new Vector3(0,0,1),0.2); | |
} | |
@onKeyboardEvent([84], KeyboardEventTypes.KEYUP)//T | |
private _moveStraightStop():void{ | |
this._pressedForwardKey = false; | |
this.animForward.stop(); | |
this.animIdle.start(true,1.0,this.animIdle.from,this.animIdle.to, false); | |
} | |
@onKeyboardEvent([70], KeyboardEventTypes.KEYDOWN)//F | |
private _mmaKick():void{ | |
if ( this._pressedKickKey == false){ | |
this.animIdle.stop(); | |
this._pressedKickKey =true; | |
} | |
this.animMmaKick.start(false,1.0,this.animMmaKick.from,this.animMmaKick.to, false); | |
// if (this.animMmaKick.targetedAnimations.animation.currentFrame ==73){ | |
this._impluseShot(); | |
// } | |
} | |
@onKeyboardEvent([70], KeyboardEventTypes.KEYUP)//F | |
private _mmaKickStop():void{ | |
} | |
private _impluseShot():void{ | |
const ballInstance = this._ball.createInstance("ballInstance"); | |
ballInstance.position.copyFrom(this._ball.getAbsolutePosition()); | |
ballInstance.scaling = new Vector3(10,10,10); | |
ballInstance.isVisible=false; | |
ballInstance.physicsImpostor = new PhysicsImpostor(ballInstance, PhysicsImpostor.SphereImpostor, { mass: 1000, friction: 0.2, restitution: 0.2 }); | |
const force = this.getDirection(new Vector3(0, 0, -1000)).multiplyByFloats(this._impluseForceFactor, this._impluseForceFactor, this._impluseForceFactor); | |
var impulseMagnitude = 500000; | |
var contactLocalRefPoint = ballInstance.position; | |
var impulseDirection1 = new Vector3(0, 0, -1); | |
ballInstance.applyImpulse(impulseDirection1.scale(impulseMagnitude), ballInstance.getAbsolutePosition().add(contactLocalRefPoint)); | |
} | |
public onMessage(name: string, data: any, sender: any): void { | |
switch (name) { | |
case "myMessage": | |
// Do something... | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment