2
\$\begingroup\$

I'm making a game and I wanted to simplify some code by taking advantage of linear algebra. I'm a little stuck.

enter image description here

Let's say the player (green triangle) resides in a coordinate system where the x-axis is the gray arrow pointing right, and the y-axis is the gray arrow pointing down (y increases as it goes down, but that's besides the point).

I want to define some basic movements for my player, like forward, backwards, and strafe. Currently, I have these movements defined with respect to the the gray coordinate system. So if we take the first green triangle for example, giving it the "forward" command would correctly move it to the right.

However, I want these commands to act with respect to the coordinate frame of the player. For example, giving the "forward" command to the second green triangle would move it up with respect to the gray coordinate system, but it currently just moves right.

I tried accomplishing this by defining an arbitrary coordinate system on the player.

$$\textbf{x} = (1, 0)^T$$

$$\textbf{y} = (0, 1)^T$$

Whenever the player rotates $\theta$, I compute the new axes for the player.

$$\textbf{x'} = R(\theta)\textbf{x}$$

$$\textbf{y'} = R(\theta)\textbf{y}$$

Now, let's say I have some velocity vector $\textbf{v}$ that is added to the current position $\textbf{p}$. The velocity vector for the "forward" action would be $(s, 0)$ for some speed $s$.

I tried computing $$\textbf{p'} = \textbf{p} + (\textbf{x'} \cdot \textbf{v}, \textbf{y'} \cdot \textbf{v})^T$$ but this is giving some nonsensical results.

So, I'm confused about what it means to define a arbitrary coordinate system with respect to some object (which rotates and translates with the object), that resides in another static coordinate system. I'm not sure if I'm using the right vocabulary here, so please correct me if I said anything wrong.

And out of curiosity, can we model this as a “change of basis”? I’m guessing no since the transformation can be nonlinear.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.