Skip to content

Commit

Permalink
ESM First Person Controller (playcanvas#7252)
Browse files Browse the repository at this point in the history
* Rewrote FPS scripts into ESM

* Renamed to character controls and script to first person controller

* Removed comma

* Renamed character controls to first person controller

* Updated keyboard mouse input

* Combined inputs inside fps controller class

* Re-exposed all attributes for each input

* Added missing definitions of lastFoward and lastStrafe back in
  • Loading branch information
kpal81xd authored Jan 13, 2025
1 parent bbb7b07 commit 9012f37
Show file tree
Hide file tree
Showing 3 changed files with 1,121 additions and 912 deletions.
12 changes: 5 additions & 7 deletions examples/src/examples/camera/first-person.example.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// @config DESCRIPTION <div style='text-align:center'><div>(<b>WASD</b>) Move</div><div>(<b>Space</b>) Jump</div><div>(<b>Mouse</b>) Look</div></div>
import { deviceType, rootPath } from 'examples/utils';
import { deviceType, fileImport, rootPath } from 'examples/utils';
import * as pc from 'playcanvas';

const { FirstPersonController } = await fileImport(`${rootPath}/static/scripts/esm/first-person-controller.mjs`);

const canvas = /** @type {HTMLCanvasElement} */ (document.getElementById('application-canvas'));
window.focus();

Expand All @@ -23,7 +25,6 @@ const gfxOptions = {

const assets = {
map: new pc.Asset('map', 'container', { url: `${rootPath}/static/assets/models/fps-map.glb` }),
script: new pc.Asset('script', 'script', { url: `${rootPath}/static/scripts/camera/first-person-camera.js` }),
helipad: new pc.Asset(
'helipad-env-atlas',
'texture',
Expand Down Expand Up @@ -112,15 +113,12 @@ function createCharacterController(camera) {
restitution: 0
});
entity.addComponent('script');
entity.script.create('characterController', {
entity.script.create(FirstPersonController, {
attributes: {
camera: camera,
camera,
jumpForce: 850
}
});
entity.script.create('desktopInput');
entity.script.create('mobileInput');
entity.script.create('gamePadInput');

return entity;
}
Expand Down
Loading

0 comments on commit 9012f37

Please sign in to comment.