The basic setup I'm working with is a cube rendered in-Engine (Panda3d, although I only am looking for a generalized solution) as well as a 2d square on one face of the cube. The eventual outcome I'm looking for is for the player to control the 2d square with WASD as it moves on the faces of the cube (never anywhere else)
My current solution is to have the player object contain two unit vectors: forward
and right
. The forward
vector controls with direction the player moves when W/S are pressed, and right
controls the direction for A/D. So for example, the player starts out on the near Y face (y = -1), so the vectors are:
forward = {0, 0, 1}
right = {1, 0, 0}
When the player's position exceeds the a boundary of the cube (e.g. on a unit-cube, the Z coordinate is greater than 1), forward
and right
are recalculated for the new face the square should be on, and the square is appropriately rotated.
I've started to get this working, however, in this early implementation, there is a fixed camera. Eventually, the camera is planned to move to be orthogonal to the face the cursor is currently on, so I realized that what signifies "forward" is going to vary based on the path a player takes to get to a face. My struggle is to now find an appropriate movement method to the cube-face constrained motion, with a moving camera.