Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. xna first person shooter: strafing

xna first person shooter: strafing

Scheduled Pinned Locked Moved C#
game-devtutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    James_722
    wrote on last edited by
    #1

    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.

    C 1 Reply Last reply
    0
    • J James_722

      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.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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.

      J 1 Reply Last reply
      0
      • C Christian Graus

        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.

        J Offline
        J Offline
        James_722
        wrote on last edited by
        #3

        I tried, it didn't work. the object either got stuck in place or shot up in the y direction.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups