XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

Trajectories... are throwing me off!

Last post 4/20/2008 9:45 AM by MatSav. 5 replies.
  • 4/17/2008 3:10 PM

    Trajectories... are throwing me off!

    Hello people,

    Im having trouble with trajectories. my bullets are flying right but the trajectory rotation and elevation seem to be double that of the lookAt point in relation to straight ahead (0.0f rotation and 0.0f elevation).

    I have tried everything i can think of to rectify this and im sure that it is only something small, perhaps even just one line - but i still cannot do it. :(

    What i am asking is for somebody to have a look at my project and see if they can help me annihalate this little bug!

    The camera is contained within the Player class and all the relevant info in this class is within the Apply Update #region within the Update Methods #region. and declarations may need to be messed with. in Main Game.cs, the code initialising each new bullet as it is fired is in the Update Methods #region, in the sub #region Gameplay.

    Here is my project.

    Much obliged if anyone can help me out of this pickle!

    Thanks, M@t.

    XNA is Shawn's game. We just play it.

    foreach (Day day in life) { experience++; }
  • 4/18/2008 9:33 AM In reply to

    Re: Trajectories... are throwing me off!

    looks like i have to bump... :(
    XNA is Shawn's game. We just play it.

    foreach (Day day in life) { experience++; }
  • 4/19/2008 1:37 PM In reply to

    Re: Trajectories... are throwing me off!

    You'll be more likely to get help if someone doesn't have to go digging through your code just to find what you're talking about. Paste the faulty code snippet here and more people will be able to take a look at it and offer a solution.
    __________________________________________________
    Check out my XNA project here:
    http://people.cis.ksu.edu/~ccaywood/astroblast/
  • 4/19/2008 11:31 PM In reply to

    Re: Trajectories... are throwing me off!

    Hi, I downloaded your game, but I'm not really sure what problem you're having. Can you explain it with a little more detail?
  • 4/20/2008 9:28 AM In reply to

    Re: Trajectories... are throwing me off!

    While playing with your bullet rotations (line 401, player.cs), I found the smaller you make the orientation float, the closer it gets you to what you want. For instance;

    Matrix bulletRotation = Matrix.CreateRotationY(orientation / 10000 );
    Matrix bulletElevationMatrix = Matrix.CreateRotationX(elevation / 10000);

    seems to get you what you want. (where I put 10000, you had 4). But your code is too complex to quickly see why this is & I don't have time to dive into it deeply enough.


    Unlock The *I don't use 3 angles in a Vector3 for rotations anymore* Achievement Here
  • 4/20/2008 9:45 AM In reply to

    Re: Trajectories... are throwing me off!

    Answer
    Reply Quote

    Thanks for your input guys... i thought this post dead when it had gone to the second page, so i bumped it and left it. i figured this problem out yesterday when i pressed pageUp and flew around (mostly to view models and stuff) i realised that then, the bullets were exactly on target. i then got rid of bulletTransform and the other bullet matrices and instead used transform3D, which multiplied the elevationMatrix used in the free roaming mode in just before the rotation. anyway, it works now and thanks for replying. this is the code as it stands now, if anybody is interested...

    Relevant Section of Player.cs

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    orientation += MathHelper.TwoPi;
            if (orientation > 0)
              orientation -= MathHelper.TwoPi;
            direction = new Vector3(0, 0, 0);
            if (goingForward)
              direction.Z -= 1;
            if (goingBackward)
              direction.Z += 1;
            if (strafingLeft)
              direction.X -= 1;
            if (strafingRight)
              direction.X += 1;
    if (lookingUp)
    {
    if (elevation + (invertedY * (MathHelper.Pi * 0.025f * difference.Y * dt)) < 1.5f)
    elevation += invertedY * (MathHelper.Pi * 0.025f * difference.Y * dt);
    }
    if (lookingDown)
    {
    if (elevation - (invertedY * (MathHelper.Pi * 0.025f * difference.Y * dt)) > -1.5f)
    elevation -= invertedY * (MathHelper.Pi * 0.025f * difference.Y * dt);
    }
            if (lookingLeft)
    orientation += MathHelper.Pi * 0.03125f * difference.X * dt;
            if (lookingRight)
    orientation -= MathHelper.Pi * 0.03125f * difference.X * dt;
    translation = Matrix.CreateTranslation(direction * speed * sprint);
    orientationMatrix = Matrix.CreateRotationY(orientation);
    elevationMatrix = Matrix.CreateRotationX(elevation);
    translation3D = translation * elevationMatrix * orientationMatrix;
    translation = translation * orientationMatrix;

    if (collisionsDisabled)
    position += translation3D.Translation;
    else
    {
    if (collDetect.isNotOutOfBounds(position + (translation.Translation * Vector3.UnitX)))
    position += translation.Translation * Vector3.UnitX;
    if (collDetect.isNotOutOfBounds(position + (translation.Translation * Vector3.UnitZ)))
    position += translation.Translation * Vector3.UnitZ;
    else
    {
    if (position.Z < -149f && Math.Abs(position.X) < 2f)
    {
    position.Z = 150f;
    if (level < 4)
    level++;
    }
    }
    if (position.Y != 2.75f)
    position.Y = 2.75f;
    if (position.X >= 11f)
    position.X = 10.5f;
    else if (position.X <= -11f)
    position.X = -10.5f;
    if (position.Z > 150f)
    position.Z = 150f;
    else if (position.Z < -150f)
    position.Z = -150f;
    }
            lookAt = new Vector3(0, 0, -1);
    lookAt = (Matrix.CreateTranslation(lookAt) * elevationMatrix * orientationMatrix).Translation;
            lookAt += position;

     

    Relevant Section of MainGame.cs

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    if (player.shoot)
    {
       for (int i = 0; i < GameConstants.playerClip; i++)
       {
          if (!playerBulletIdea.isActive)
          {
             playerBulletIdea.direction = player.translation3D.Forward;
    playerBulletIdea.position = player.position + (playerBulletIdea.direction * 0.5f);
             playerBulletIdea.isActive = true;
             break;
          }
       }
       player.shoot = false;
    }

     

    Thanks again guys.

    M@t.

    XNA is Shawn's game. We just play it.

    foreach (Day day in life) { experience++; }
Page 1 of 1 (6 items) Previous Next