Stealth games mechanics#

Show how linear algebra can be used to support basic stealth gameplay

Notebook Setup#

from IPython.display import IFrame

Introduction#

We will see in the following exercices checks about distances, line of sight and some trigonometry.

Code exercices are made with the P5.js library.

Questions#

I - Is player in front or behind ?#

You have an NPC at position x with a forward direction v

  1. How can you determine if the player position p is in front or behind of the NPC ?

  2. Implement your solution in the file st-01.html under the “WRITE CODE HERE” comment. If you are correct, your code should behave as the sample below

IFrame("./awnsers/st-01.html", width=700, height=400)

II - Field of view#

You have an NPC at position x with a forward direction v and a field of view of 60 degrees

  1. How can you determine if a given position p is inside the field of view ?

  2. Implement your solution in the file st-02.html under the “WRITE CODE HERE” comment. If you are correct, your code should behave as the sample below

IFrame("./awnsers/st-02.html", width=700, height=400)

III - Line of sight obstruction (based on radius)#

You have an NPC at position x, a player at position p, and an obstacle at position o with a given radius of 100

  1. How can you determine if the obstacle is in between the player and the NPC ?

  2. How can you determine if the obstacle is obstructing the line of sight from the player to the NPC ?

  3. Implement your solution in the file st-03.html under the “WRITE CODE HERE” comment. If you are correct, your code should behave as the sample below

IFrame("./awnsers/st-03.html", width=700, height=400)

IV - Line of sight obstruction (based on line / segment intersection)#

You have an NPC at position x, a player at position p, and some polygon obstacles (made with one or multiple segments, the positions of each segments are provided)

  1. How can you determine if the obstacle is obstructing the line of sight from the player to the NPC ?

  2. Implement your solution in the file st-04.html under the “WRITE CODE HERE” comment. If you are correct, your code should behave as the sample below

  3. How would you solve this problem in 3D space ?

IFrame("./awnsers/st-04.html", width=700, height=400)

Awnsers#

I Is player in front or behind ?#

Wip


Sources#

*Wip