Math - Vector Addition - Challenge

the offset is the square root of 10 in magnitude
the new coordinates are 8, 1 for the camera

I wasn’t sure if I needed to add or subtract vectors at first but I figured it out with some basic algebra.

p = playerPosition = (5,0)
c = cameraPosition = (2,1)
o = offsetPosition = (?,?)

I noticed:

cameraPosition = playerPosition + offsetPosition

or

c = p + o

re-arranging the formula to solve for o:
o = c - p

plugged in the vectors for c and p
o = ((2-5),(1-0)) = (-3,1)

to find what c is when p = (11,0)

c = p + o
c = ((11+ (-3)),(0+1)) = (8,1)

Camera offset is (2,1) - (5,0)
That leaves the offset to be (-3, 1)

Second position of the player P(11,0)
Camera position is (11,0) + (-3,1)= (8,1)

However I have found a different way to calculate the final/ second position of the camera.

If you subtract the second position of the player (11,0) with the first position of the player (5,0), so (11,0) - (5,0) = (6,0).

So the offset from the first position and second position of the player is (6,0)

If you add this to the camera’s first position (2,1) , you get (2,1) + (6,0) = (8,1).

Start position

  1. Player (5, 0);
  2. Camera (2, 1);
    Camera pos = (Xp - 3, Yp + 1)

Next position

  1. Player (11,0);
  2. Camera = (11 - 3, 0 + 1) = (8, 1)

Camera = (2, 1)
Player = (5, 0)
Offset = Camera - Player = (-3, 1)
Player new position = (11, 0)
Camera new position = Player new position + Offset = (8, 1)

Not sure if my approach was the common way to do it, but just looking at the vector positions and having the knowledge that we were only moving forward on the X axis 6 units the basic idea would have been to just add 6 units to the X axis for the camera to maintain the same offset…

Player start: (5,0)
Camera start: (2,1)

Offset: (-3, 1)

Player destination: (11, 0)
Camera destination: (11, 0) + (-3, 1) = (8, 1)

Here’s my work for the Camera Position challenge:

Let OP be the vector from the origin to the player position
Let OC be the vector from the origin to the camera position
Let VO be the offset between OP and OC

VO = OC - OP
VO = (2 - 5, 1 - 0)
VO = (-3, 1)

Given an OP of (5, 0), find the camera position after the player has moved along the x-axis 6 units:

OC = OP + VO
OC = (11 + -3, 0 + 1)
OC = (8, 1)

1 Like

Privacy & Terms