What is a first person camera?
It's a camera mode where you don't see the whole body of the character you control in the game (see figure 1).
Figure 1: Wolfestein Screenshot
We can separate this into two parts: the movement part and the visualization part. With the movement part the player is able to move around. With the visualization part the player is able to look around.
The Movement Part
Let's see the player from a top view (see figure 2). We will use two unit vectors: the direction vector (dir in figure 2) which direction is the one the player will use to move forward and backwards; And the right vector which direction will allow the player to move to the left and right. The letter p in figure 2 represent the position of the player.
Figure 2: A Top View of the Player
The next instructions will demonstrate how it works.
To move forward and backwards:
p = (p + dir) * speed
p = (p - dir) * speed
To move to the left and right:
p = (p + right) * speed
p = (p - right) * speed
Where the variable speed indicates how fast the player will move.
The Visualization Part
In this part, what we have to find is the LookAt point. The LookAt point is the point that the player is always looking at. To do so, we make this point depend on two angles: phi and theta (see figure 3). After that our work will reduce to just modify phi and theta in order to modify the LookAt point and make the player look everywhere.
Figure 3
The next instruction will summarize this:
LookAt = p + (sin(theta), sin(phi), cos(theta))
Movement Part + Visualization Part
Instructions:
LookAt Point Calculation:
LookAt = p + (sin(theta), sin(phi), cos(theta))
To move forward and backwards:
p = (p + M) * speed
p = (p + M) * speed
where M = | LookAt - p |
To move to the left and right:
p = (p + right) * speed
p = (p + right) * speed
IMPORTANT: we have to move both p and LookAt (at the same time) when we move the player forward, backward, right or left.



No comments:
Post a Comment