-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c3876d
commit 947eced
Showing
57 changed files
with
528 additions
and
509 deletions.
There are no files selected for viewing
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
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import RAPIER from '@dimforge/rapier2d' | ||
import { FKeyboard } from '@fibbojs/event' | ||
import type { FScene } from '../core/FScene' | ||
import type { FCharacterControllerOptions } from './FCharacterController' | ||
import { FCharacterController } from './FCharacterController' | ||
|
||
/** | ||
* @description A pre-defined character controller based on a Dynamic RigidBody. | ||
* @category Controller | ||
* @example | ||
* ```ts | ||
* import { FCapsule, FCharacterControllerD, FScene } from '@fibbojs/3d' | ||
* | ||
* const scene = new FScene() | ||
* | ||
* const capsule = new FCapsule(scene) | ||
* capsule.controller = new FCharacterControllerD(scene) | ||
* scene.addComponent(capsule) | ||
* ``` | ||
*/ | ||
export class FCharacterControllerD extends FCharacterController { | ||
constructor(scene: FScene, options: FCharacterControllerOptions) { | ||
super(scene, options) | ||
|
||
const fKeyboard = new FKeyboard(scene) | ||
fKeyboard.on(' ', () => { | ||
this.component.rigidBody?.rigidBody.applyImpulse({ x: 0, y: 0.5 }, true) | ||
}) | ||
|
||
// Initialize the rigid body | ||
this.component.initRigidBody({ | ||
rigidBodyType: RAPIER.RigidBodyType.Dynamic, | ||
lockRotations: true, | ||
...options, | ||
}) | ||
} | ||
|
||
onFrame(_delta: number): void { | ||
// Apply movement on the y axis | ||
if (this.inputs.up) { | ||
this.component.rigidBody?.rigidBody.applyImpulse({ x: 0, y: 0.15 * this.speed }, true) | ||
} | ||
else if (this.inputs.down) { | ||
this.component.rigidBody?.rigidBody.applyImpulse({ x: 0, y: -0.15 * this.speed }, true) | ||
} | ||
// Apply movement on the x axis | ||
if (this.inputs.left) { | ||
this.component.rigidBody?.rigidBody.applyImpulse({ x: -0.15 * this.speed, y: 0 }, true) | ||
} | ||
else if (this.inputs.right) { | ||
this.component.rigidBody?.rigidBody.applyImpulse({ x: 0.15 * this.speed, y: 0 }, true) | ||
} | ||
} | ||
} |
Oops, something went wrong.