Skip to content

Instantly share code, notes, and snippets.

@flushpot1125

flushpot1125/p_player.ts

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