VR teleportation offset.

64 Views Asked by At

enter image description here

Knowing $\vec{A}$ and $\vec{B}$, how do i find the coordinates for $\vec{C}$ in 3d space? The vectors are in 3d space while the picture looks at them from a perspective that they are effectively on the same plane.

Context: I need to solve this for the VR project I am working on. The player is able to teleport around. When teleporting, the center of the playspace is placed on the point that was aimed at. However this feels weird so I need to add the offset between the centre of the playspace and the players head which is vector A. However if I do not remove the height of the offset, the player's head gets placed on ground level. This is easily fixed by simply setting A.z = 0. But since the surface the player teleports on is a spaceship, the player can quickly find themself sideways. Then I need to remove the heighy relative to the ships orientation, which is vector B. I am interrested in math, but right now I need answers and not hint. Thank you in advance :3

1

There are 1 best solutions below

6
On BEST ANSWER

HINT

  • calculate the vector projection of $\vec A$ on $\vec B$ that is $a\vec B$ for some $a\in\mathbb{R}$
  • then $\vec C= \vec A - a\vec B$

How to find the projection?

It's a property of the dot product that:

$$\vec A \cdot \vec B=|\vec A||\vec B|\cos \theta$$

Thus, if $\vec u$ is a unit vector:

$$\vec u \cdot \vec A=|\vec u||\vec A|\cos \theta=|\vec A|\cos \theta$$

is the scalar projection of $\vec A$ on $\vec u$ and

$$(\vec u \cdot \vec A)\vec u$$

is the vector projection of $\vec A$ on $\vec u$.

Now the unitary vector for $\vec B$ is

$$\vec u= \frac{\vec B}{|\vec B|}$$

Thus the vector projection of $\vec A$ on $\vec B$ is given by

$$\left(\frac{\vec B}{|\vec B|}\cdot \vec A\right)\frac{\vec B}{|\vec B|}=\left(\frac{\vec B}{|\vec B|^2}\cdot \vec A\right)\vec B$$