Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@flushpot1125
Last active July 23, 2020 23:57
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/1c4d89828dc22e07c2d909d3ff587f9b to your computer and use it in GitHub Desktop.
Save flushpot1125/1c4d89828dc22e07c2d909d3ff587f9b to your computer and use it in GitHub Desktop.
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