xna first person shooter: strafing
-
I am creating a (first person shooter)-ish video game for my comp. sci. class and I can't get my character to strafe properly. I can have it move forwards and backwards but not side to side (at least not relative the the object, only the world). here is the code to move the object forward.
if (keyboardState.IsKeyDown(Keys.W))
{Vector3 pos = GetMissileMuzzlePosition(); missileLauncherHead.velocity = missileLauncherHead.position - new Vector3(pos.X, 0, pos.Z); missileLauncherBase.velocity = new Vector3(0.0f, 0.0f, 0.0f); missileLauncherHead.position -= missileLauncherHead.velocity; missileLauncherBase.position -= missileLauncherBase.velocity; }
and here's the code to make the object (its a cannon at this point) move to the left.
if (keyboardState.IsKeyDown(Keys.A))
{
Vector3 pos = GetMissileMuzzlePosition();
Vector3 refer = new Vector3(missileLauncherHead.position.X + 5, missileLauncherHead.position.Y,missileLauncherHead.position.Z);
missileLauncherHead.velocity = refer - missileLauncherHead.position;
missileLauncherBase.velocity = new Vector3(5.0f, 0.0f, 0.0f);
missileLauncherHead.position -= missileLauncherHead.velocity;
missileLauncherBase.position -= missileLauncherBase.velocity;
}I a complete noob when it comes to vectors. I literally just learned how to do this in my calculus/vectors couse a few weeks back.
-
I am creating a (first person shooter)-ish video game for my comp. sci. class and I can't get my character to strafe properly. I can have it move forwards and backwards but not side to side (at least not relative the the object, only the world). here is the code to move the object forward.
if (keyboardState.IsKeyDown(Keys.W))
{Vector3 pos = GetMissileMuzzlePosition(); missileLauncherHead.velocity = missileLauncherHead.position - new Vector3(pos.X, 0, pos.Z); missileLauncherBase.velocity = new Vector3(0.0f, 0.0f, 0.0f); missileLauncherHead.position -= missileLauncherHead.velocity; missileLauncherBase.position -= missileLauncherBase.velocity; }
and here's the code to make the object (its a cannon at this point) move to the left.
if (keyboardState.IsKeyDown(Keys.A))
{
Vector3 pos = GetMissileMuzzlePosition();
Vector3 refer = new Vector3(missileLauncherHead.position.X + 5, missileLauncherHead.position.Y,missileLauncherHead.position.Z);
missileLauncherHead.velocity = refer - missileLauncherHead.position;
missileLauncherBase.velocity = new Vector3(5.0f, 0.0f, 0.0f);
missileLauncherHead.position -= missileLauncherHead.velocity;
missileLauncherBase.position -= missileLauncherBase.velocity;
}I a complete noob when it comes to vectors. I literally just learned how to do this in my calculus/vectors couse a few weeks back.
I would expect that if changing the X value moves you forward, then changing the Y value would move you side to side. You're reversing the vector. Remove the component that moves you forward and replace a 0 with the amount to move left or right.
Christian Graus Driven to the arms of OSX by Vista.
-
I would expect that if changing the X value moves you forward, then changing the Y value would move you side to side. You're reversing the vector. Remove the component that moves you forward and replace a 0 with the amount to move left or right.
Christian Graus Driven to the arms of OSX by Vista.