Skip to content

Commit

Permalink
Add FPS Controller example (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
willeastcott authored Jan 17, 2025
1 parent a9643ab commit 9b6671e
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 2 deletions.
Binary file added examples/assets/models/fps-map.glb
Binary file not shown.
4 changes: 4 additions & 0 deletions examples/assets/models/fps-map.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The low poly fps tdm game map model has been obtained from this address:
https://sketchfab.com/3d-models/de-dust-2-with-real-light-4ce74cd95c584ce9b12b5ed9dc418db5
It's distributed under CC license:
https://creativecommons.org/licenses/by/4.0/
2 changes: 1 addition & 1 deletion examples/car-configurator.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<pc-module name="DracoDecoderModule" glue="modules/draco/draco.wasm.js" wasm="modules/draco/draco.wasm.wasm" fallback="modules/draco/draco.js"></pc-module>
<!-- Assets -->
<pc-asset id="camera-controls" src="../node_modules/playcanvas/scripts/esm/camera-controls.mjs" preload></pc-asset>
<pc-asset id="camera-frame" src="../node_modules/playcanvas/scripts/utils/camera-frame.mjs" preload></pc-asset>
<pc-asset id="camera-frame" src="../node_modules/playcanvas/scripts/esm/camera-frame.mjs" preload></pc-asset>
<pc-asset id="choose-color" src="scripts/choose-color.mjs" preload></pc-asset>
<pc-asset id="xr-controllers" src="../node_modules/playcanvas/scripts/esm/xr-controllers.mjs" preload></pc-asset>
<pc-asset id="xr-navigation" src="../node_modules/playcanvas/scripts/esm/xr-navigation.mjs" preload></pc-asset>
Expand Down
56 changes: 56 additions & 0 deletions examples/fps-controller.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
<title>PlayCanvas Web Components - First Person Camera</title>
<script type="importmap">
{
"imports": {
"playcanvas": "../node_modules/playcanvas/build/playcanvas.mjs"
}
}
</script>
<script type="module" src="../dist/pwc.mjs"></script>
<link rel="stylesheet" href="css/example.css">
</head>
<body>
<pc-app>
<!-- Modules -->
<pc-module name="Ammo" glue="modules/ammo/ammo.wasm.js" wasm="modules/ammo/ammo.wasm.wasm" fallback="modules/ammo/ammo.js"></pc-module>
<!-- Assets -->
<pc-asset id="first-person-camera" src="../node_modules/playcanvas/scripts/esm/first-person-controller.mjs" preload></pc-asset>
<pc-asset id="static-body" src="scripts/static-body.mjs" preload></pc-asset>
<pc-asset id="lake-bed" src="assets/skies/dry-lake-bed-2k.hdr" preload></pc-asset>
<pc-asset id="map" src="assets/models/fps-map.glb" preload></pc-asset>
<!-- Scene -->
<pc-scene>
<!-- Sky -->
<pc-sky asset="lake-bed" lighting></pc-sky>
<!-- Camera (with XR support) -->
<pc-entity name="camera controller" position="5 2 10">
<pc-entity id="camera" position="0 0.9 0">
<pc-camera></pc-camera>
</pc-entity>
<pc-collision type="capsule" radius="0.5" height="2"></pc-collision>
<pc-rigidbody type="dynamic" angular-factor="0 0 0" mass="100" friction="0.5" restitution="0"></pc-rigidbody>
<pc-scripts>
<pc-script name="firstPersonController"></pc-script>
</pc-scripts>
</pc-entity>
<!-- Light -->
<pc-entity name="light" rotation="45 0 0">
<pc-light></pc-light>
</pc-entity>
<!-- Map -->
<pc-entity name="map">
<pc-model asset="map"></pc-model>
<pc-scripts>
<pc-script name="staticBody"></pc-script>
</pc-scripts>
</pc-entity>
</pc-scene>
</pc-app>
<script type="module" src="js/example-ui.mjs"></script>
</body>
</html>
1 change: 1 addition & 0 deletions examples/js/example-list.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const examples = [
{ name: 'Animation', path: 'animation.html' },
{ name: 'Basic Shapes', path: 'basic-shapes.html' },
{ name: 'Car Configurator', path: 'car-configurator.html' },
{ name: 'FPS Controller', path: 'fps-controller.html' },
{ name: 'Gaussian Splatting', path: 'splat.html' },
{ name: 'GLB Loader', path: 'glb.html' },
{ name: 'Physics', path: 'physics.html' },
Expand Down
16 changes: 16 additions & 0 deletions examples/scripts/static-body.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Script } from 'playcanvas';

export class StaticBody extends Script {
initialize() {
this.entity.findComponents('render').forEach((render) => {
const entity = render.entity;
entity.addComponent('rigidbody', {
type: 'static'
});
entity.addComponent('collision', {
type: 'mesh',
renderAsset: render.asset
});
});
}
}
2 changes: 1 addition & 1 deletion examples/solar-system.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<!-- Modules -->
<pc-module name="Basis" glue="modules/basis/basis.wasm.js" wasm="modules/basis/basis.wasm.wasm" fallback="modules/basis/basis.js"></pc-module>
<!-- Assets -->
<pc-asset id="camera-frame" src="../node_modules/playcanvas/scripts/utils/camera-frame.mjs" preload></pc-asset>
<pc-asset id="camera-frame" src="../node_modules/playcanvas/scripts/esm/camera-frame.mjs" preload></pc-asset>
<pc-asset id="solar-system" src="scripts/solar-system.mjs" preload></pc-asset>
<pc-asset id="stars" src="assets/skies/stars.png" preload></pc-asset>
<pc-asset id="sun" src="assets/models/planets/sun.glb" preload></pc-asset>
Expand Down

0 comments on commit 9b6671e

Please sign in to comment.