DirectX First Person Shooter Projectile?

Hello,
I have a first person camera setup and am wondering how do I make a projectile fire at the direction/angle the camera is facing at the center like in most first person shooters


Answer this question

DirectX First Person Shooter Projectile?

  • DC Martin

     

    In the October 2005 SDK there is a sample that do what you want to do

    It shoots orange ball in a room...

    (a first person shooter with oriented projectile with camera view)

    So I would look at that sample to see how it's done

    The other way could be to use the matrix of the Lookat function

    this take 2 pts and produce a matrix position and orientation...

    This look trivial but it's not...

    This LookAt matrix could also be use to orient stuff in your game

    by creating a matrix that you define by telling 2 pts in 3D

    and then using that matrix as the WOLRD matrix

     


  • oren

    I'm using the December 2005 SDK right now and didn't come accross that sample yet I'll look for it I appreciate that.

    I think I pretty much got the projectile movement worked out using a simple and straight forward method with little math involved, but the next question that would have definately came up next was about the projectile's orientation and I think you just answered that with the concept of using the existing matrix to orientate the projectile object, so thank you very much!

    I tried several other methods using various over packed and lengthy C++ samples but none of them worked, then I tried methods from post on another forum and I couldn't get it to work for a moving camera, so I went ahead and tried to use same method as is used to move the camera eye position based on the LookAt with some subtraction and this is what it looks like:
    vecProjectile.X -= CameraVectors.vecCameraLook.X * -moveSpeed * elapsedTime
    vecProjectile.Y -= CameraVectors.vecCameraLook.Y * -moveSpeed * elapsedTime
    vecProjectile.Z -= CameraVectors.vecCameraLook.Z * -moveSpeed * elapsedTime


    Or it can be written as such:
    vecForward = CameraVectors.vecCameraLook 'Set forward vector when ready to fire. (SKIP THIS ONCE FIRE BUTTON IS PRESSED AND CONTINUE TO THE CODE BELOW.)

    vecForward.Multiply(-moveSpeed * elapsedTime) 'Set the amount to move projectile.
    vecProjectileCurrentPos.Subtract(vecForward) 'Move projectile forward/outward.


    There was another user here that mentioned using a ray, position and lookat vectors and subtract the position from the lookat to produce the ray then do intersection test on mesh objects, I already know how to do that and wanted to send a visible projectile from the very center of a crosshair, so the formula above works.

    PS: That other persons post is now missing from this thread but I'd like to thank them as well since it reminded me about the ray intersection.

  • DirectX First Person Shooter Projectile?