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

Laser Sight for 3D game

Last post 24/05/2009 17:03 by jwatte. 4 replies.
  • 23/05/2009 5:21

    Laser Sight for 3D game

    I am creating a 3rd person shooter game in XNA. I have been searching everywhere to try and find out how to impliment a laser sight for my gun. This probably goes without explanation, but I basically want to have a laser that points to whatever I am shooting at. I also would like it to be such that I can add a glow and flicker to it. Any help?
  • 23/05/2009 5:55 In reply to

    Re: Laser Sight for 3D game

    This overview should get you close,

    Create a cylinder with a small radius, modeled so that one end is at 000 and the other at 00,-1.   Use subtraction and Vector3.Distance to find the distance and direction from the end of the weapon to the target.  Scale the cylinder in the Z direction by the distance from the end of the gun to the target (createScale(1,1,Distance).  create a world matrix for the cylinder with the direction to the target as Forward and the end of the weapon as the position (Matrix.createWorld(direction,position,up).      Then, you can swap out textures each frame to create some type of animation on the texture, or if you're using your own shader the sky's the limit.

    Best,
    Byron
    ..shaders make you feel... powerful, or very very stupid.
    http://drjbn.spaces.live.com/
  • 24/05/2009 10:29 In reply to

    Re: Laser Sight for 3D game

    Thanks for the reply Byron. This may seem like a silly questions, but i'm not sure how to create the cylinder. Is this something I would do in Maya, and then export into my game, or can this be done directly in XNA?

    Thanks
  • 24/05/2009 11:51 In reply to

    Re: Laser Sight for 3D game

    Technically it could be done in XNA, but the simplest route would be to do it with a 3d program (e.g., Maya), export to .x or .fbx & load it through the content manager.

    Best,
    Byron
    ..shaders make you feel... powerful, or very very stupid.
    http://drjbn.spaces.live.com/
  • 24/05/2009 17:03 In reply to

    Re: Laser Sight for 3D game

    You can also just stretch a billboarded quad from source to destination.

    The main important bit is to find what the laser "hits" and only draw the quad until that point, because whatever it hits should shadow whatever is behind it.
    Jon Watte, Direct3D MVP
    Tweets, occasionally
    kW X-port 3ds Max .X exporter
    kW Animation source code
Page 1 of 1 (5 items) Previous Next