@matematrolii/sketchbook
Version:
3D matematrolii playground built on three.js and cannon.js
56 lines (44 loc) • 1.36 kB
text/typescript
import {
CharacterStateBase,
EndWalk,
JumpRunning,
Sprint,
} from "./_stateLibrary";
import { Idle } from "./Idle";
import { Character } from "../Character";
export class Walk extends CharacterStateBase {
constructor(character: Character) {
super(character);
//this.character.setArcadeVelocityTarget(0.8);
this.character.setArcadeVelocityTarget(0.3);
//this.playAnimation('run', 0.1);
this.playAnimation("walk", 0.1);
}
public update(timeStep: number): void {
super.update(timeStep);
this.character.setCameraRelativeOrientationTarget();
this.fallInAir();
}
public onInputChange(): void {
super.onInputChange();
if (this.noDirection()) {
this.character.setState(new EndWalk(this.character));
}
if (this.character.actions.run.isPressed) {
this.character.setState(new Sprint(this.character));
}
if (this.character.actions.run.justPressed) {
this.character.setState(new Sprint(this.character));
}
if (this.character.actions.jump.justPressed) {
this.character.setState(new JumpRunning(this.character));
}
if (this.noDirection()) {
if (this.character.velocity.length() > 1) {
this.character.setState(new EndWalk(this.character));
} else {
this.character.setState(new Idle(this.character));
}
}
}
}