1 Reply Latest reply on May 21, 2006 7:36 AM by Mazuho

    Rotating issues

      In a 3dgame I am currently developing I am having a bullet "spawn" from a model resource every time the user shoots with his/her tank. Let's say that when the game starts the turret is in position A. The user rotates the turret x degrees and fires, and the bullet should fly away in the direction the barrel is pointing in. My problem now is that the bullet always goes in the same direction. It gets spawned from the tip of the barrel just as it should, but if I make a 180 degree turn, the bullet flies into the tank instead.

      This is the code for positioning the bullet when it gets spawned:

      bullet = w.newmodel("bullet"&string(pcount), bulletR)
      bullet.worldposition = w.model("turrettarget").worldposition

      --pTurretEnd is a small invicible box at the end of the barrel

      This is the code for the trajectory of the bullet:
      --BulletV = vector(-20,0,0) BulletH = vector(0,0,0.1)

      Any ideas?
        • 1. Re: Rotating issues
          Mazuho Level 1
          Okay, I solved it by doing the following:
          1. Getting a vector from the beginning of the barrel.
          2.Getting a vector from the end of the barrel.
          3. vector c = vector a - vector b
          4. normalized vector c
          5. translated the bullet along the direction vector now aquired (vector c)

          Hope someone finds this useful