Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Your forward vector should always equal the up vector of your camera in this case(where you are rotating the camera around the world) after you have applied the rotation to it. For the right vector, you can take the cross product of the camera up vector and the camera look at vector, keeping in mind that the order that you do the crossproduct matters and depending on what coordinate system you are using (right or left handed).

share|improve this answer
    
Thank you, this is exactly what I needed. –  FunkyDelPueblo Mar 1 '13 at 20:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.