Last active
July 23, 2020 23:57
-
-
Save flushpot1125/1c4d89828dc22e07c2d909d3ff587f9b to your computer and use it in GitHub Desktop.
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, Vector3, KeyboardInfo, KeyboardEventTypes,Space} from "@babylonjs/core"; | |
import { visibleInInspector, onKeyboardEvent} from "../tools"; | |
export default class p_player extends Mesh { | |
@visibleInInspector("KeyMap", "Left Key", "a".charCodeAt(0)) | |
private _leftKey: number; | |
@visibleInInspector("KeyMap", "Right Key", "d".charCodeAt(0)) | |
private _rightKey: number; | |
private constructor() { } | |
/** | |
* Called on the scene starts. | |
*/ | |
public onStart(): void { | |
// ... | |
} | |
/** | |
* Called each frame. | |
*/ | |
public onUpdate(): void { | |
// ... | |
} | |
@onKeyboardEvent([65], KeyboardEventTypes.KEYDOWN) | |
private _moveLeft():void{ | |
if( (this.position.z >= -21)&&(this.position.z <= 21) ){ | |
this.translate( new Vector3(0,0,0.5),6,Space.WORLD); | |
console.log(this.position.z); | |
} | |
} | |
@onKeyboardEvent([68], KeyboardEventTypes.KEYDOWN) | |
private _moveRight():void{ | |
if( (this.position.z >= -21)&&(this.position.z <= 21) ){ | |
this.translate( new Vector3(0,0,-0.5),6,Space.WORLD); | |
console.log(this.position.z); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment