Here are some points to keep in mind:
1. Objects in the tutorial project never move (though they could).
2. The camera (player) starts at 0,0,0 (and 0 rotation) - so that means the obejcts you see on screen have NO translation applied (other than perspective and size for the view)
3. As the camera (player) moves, the camera location is simply subtracted from all object positions in the world to find their new positions relative to the player's movement (the objects x,y,z never change in this case).
So, let's assume the player NEVER moves. The player (camera) is at 0,0,0 (z,y,z) facing angle 0 on the Y axis (straight down Z+) and thus if you create an object at 0,0,0 and fire it down Z+, it will work. The trick then is to start at the player's (camera's) position, so that when the camera's position is subtracted from the objects position, it begins at the translated position of 0,0,0. ;) More direct to the point, just make the projectile start at the player's position and create a 3D direction vector facing the direction.
First, you need a non-translated direction:
This is a "normalized" vector (no absolute values > 1 [so you can multiply it against values for magnitude]) facing down Z+. If the player never rotates, this is all you need! :) However, when the player turns, you need to rotate the vector. I have the functions there for you already:
newX = RotateXZForX(X, Z, CameraYRotation)
newZ = RotateXZForZ(X, Z, CameraYRotation)
(Y is 0, unless you want to angle an object up or down [in which case there are functions for that as well])
Note: NEVER change X or Z before the second line (before newZ is set), otherwise madness will ensue! :)
Hope that helps! When you get your game finished, post a link here. 8)JoyfulDreamer2013-05-25 21:24:35
Jack of all trades, and master of some.