Skip to content

Commit 59f5235

Browse files
authored
Added basic 3D FPP example of movement and look around. (#131)
* Added basic 3D FPP example of movement and look around. * Fixed name of the character controller script.
1 parent 31500dd commit 59f5235

40 files changed

+1918
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
path_settings {
2+
path: "**"
3+
profile: "Default"
4+
}
5+
profiles {
6+
name: "Default"
7+
platforms {
8+
os: OS_ID_GENERIC
9+
formats {
10+
format: TEXTURE_FORMAT_RGBA
11+
compression_level: BEST
12+
compression_type: COMPRESSION_TYPE_DEFAULT
13+
}
14+
mipmaps: false
15+
max_texture_size: 0
16+
premultiply_alpha: true
17+
}
18+
}

movement/3d_fps/collection.png

159 KB
Loading

movement/3d_fps/example.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
tags: movement
3+
title: First-person 3D camera and movement
4+
brief: Control a first-person camera using WASD and mouse to look with cursor lock.
5+
author: Defold Foundation
6+
scripts: character_controller.script
7+
thumbnail: collection.png
8+
---
9+
10+
This example shows how to build a simple first-person controller for a 3D scene. You can look around with the mouse and move on the XZ plane using the keyboard (WSAD).
11+
12+
## What you'll learn?
13+
- How to implement a FPP camera with mouse to look around.
14+
- How to lock/unlock the mouse cursor for immersive camera control.
15+
- How to move on a simple XZ plane logic with keyboard input.
16+
17+
## Controls
18+
| Input | Action |
19+
|------------------------|------------------------------------------------------|
20+
| Left mouse click | Lock the cursor and enable mouse look |
21+
| Mouse movement | Rotate camera |
22+
| `Esc` | Unlock the cursor |
23+
| `W`/`S`/`A`/`D` | Move forward/backward/left/right on the ground plane |
24+
25+
## How it works?
26+
When the cursor is locked, the script reads mouse movement deltas and rotates the camera accordingly. Movement is normalized to keep a consistent speed in all directions and is clamped within a square area so you cannot wander off the demo scene.
27+
28+
Example collection consists of 3 main parts:
29+
30+
- `character` - The player character game object includes:
31+
- A *script* `character_controller.script` component that implements mouse look, cursor lock/unlock, and WASD movement.
32+
- A *camera* component configured with perspective projection.
33+
34+
- `scene` - the models used to create a basic 3D environment:
35+
- Ground plane scaled to form a walkable area with prototype texture
36+
- Walls built from simple cube models with prototype textures
37+
- Some decorative trees
38+
39+
- `gui` - An on-screen GUI with short instructions.
40+
41+
![](collection.png)
42+
43+
### Assets
44+
Tree models with textures by Kay Louseberg: https://kaylousberg.itch.io/kaykit-forest
45+
Prototype textures for Defold by Visionaire: https://github.com/Thevisionaire1/3Deforms
46+
47+
## Script
48+
49+
Tuning parameters are defined at the top of `character_controller.script`:
50+
- `look_sensitivity` (degrees per pixel) controls how fast the camera rotates
51+
- `move_speed` (world units per second) controls walking speed
52+
- `move_limit` (half-size in world units) clamps movement within bounds
53+

0 commit comments

Comments
 (0)