3d bullet motion?

This is a discussion on 3d bullet motion? within the Game Programming forums, part of the General Programming Boards category; OK, I've gotten as far as wireframe modeling with this tutorial , and now I want to turn it into ...

  1. #1
    GA ichijoji's Avatar
    Join Date
    Nov 2002

    3d bullet motion?

    OK, I've gotten as far as wireframe modeling with this tutorial, and now I want to turn it into a game. The problem is that I'm a little new to this whole matrix thing and I'm not really sure how to make a bullet move in a certain direction. If I was doing it in 2d I would do something like this:
    bullet.x += bullet.speed * cos(bullet.th);
    bullet.y += bullet.speed * sin(bullet.th);
    but I'm not really sure how to do something like that in 3d. Does anyone know how I can adapt this matrix stuff for motion?

    also: I've attached what I've got so far (I added the keyboard stuff as an afterthought, it works best with a joystick), and if you need alleg40.dll you can get it here.
    Illusion and reality become impartiality and confidence.

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    your best bet is to use a direction vector for your bullet. you can obtain this vector as follows.

    directionVec = DestinationPoint - CurrentPoint

    then scale the magnitude to the speed of the bullet.

    then at each frame move the bullet to the end of the obtained vector and you'll have the resulting flight! (note you can translate the vector with respect to the movement instead of calculating it each time assuming the bullet flys in a straight line ie. direction doesnt change)

    im sure there are other approaches but this is just one example using your new found linear algebra skillz.

  3. #3
    Join Date
    Jan 2003
    CurrentPosition= InitialPosition+ InterpolatePercent * (End - Initial).

    InterpolatePercent is a decimal between 0 and 1, with 0 being the starting point and 1 being the end point. CurrentPosition and InitialPosition are points, End - Initial is the direction the bullet is travelling in. Most games dont' use this for bullets I don't think, rather they just get the ray the gun barrel is pointing in when it is fired and they test it for intersections.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3D starfield
    By VirtualAce in forum Game Programming
    Replies: 6
    Last Post: 06-26-2003, 12:40 PM
  2. 3D SDK for C++ programmers
    By chand in forum Game Programming
    Replies: 2
    Last Post: 05-20-2003, 07:38 AM
  3. pic movement
    By pode in forum Game Programming
    Replies: 31
    Last Post: 08-21-2002, 09:30 PM
  4. Allegro help-o
    By Vicious in forum Game Programming
    Replies: 109
    Last Post: 06-11-2002, 08:38 PM
  5. 3d engines
    By Unregistered in forum Game Programming
    Replies: 7
    Last Post: 12-17-2001, 10:19 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21