How to restrict the camera to an entity’s bounding box?
In order to set boundaries to the user navigation (for instance, staying inside a room), you can restrict the camera’s position to a bounding box.
The idea is:
- get the Bounding Box (ie: AABB) of the bounding entity (eg: the scene_ref to the room).
- on each frame, check if the camera is within the bounding box
- if the camera is outside, travel towards the center of the bounding box until the camera is within the bounds.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37