Bullets

Started by
3 comments, last by bballmitch 18 years ago
So i have a variable of type Bullet: Bullet *b = new Bullet(); and then everytime I left click with the mouse, I have this code: b.init(0,0,0, cos(view_angle)*1000, sin(sight)*1000, sin(view_angle)*1000, 1000); Where the first 3 parameters are the initial location of the bullet, the second three are the bullets destination, and the last parameter is the speed of the bullet. Do not worry about the speed right now. Here's my problem. I want to make my character move, so the first three parameters should be changed to posX, posY, posZ which are the position of my main character. But how do I change the second three parameters to accomplish what I want? BTW, view_angle is the angle that my character is facing. So if he's facing NorthWest, the bullet will go NorthWest. BTW #2, if my character NEVER moves, that first b.init() method works perfectly.
Mitchen Games
Advertisement
You need to transform the vector constructed from the second three arguments of your 'init' function by the character's transformation matrix. How to do this depends on what math library or API you're using. Also, the trig you're using to compute the bullet direction is incorrect (although the results will be close enough to correct that you probably haven't noticed). It should instead be (cos(yaw)*cos(pitch), sin(pitch), sin(yaw)*cos(pitch)).
what do yaw and pitch represent?

and, I'm using OpenGL, so shouldn't this work?

glPushMatrix();glTranslatef(posX, posY, posZ);b.init(0,0,0, cos(view_angle)*1000, sin(sight)*1000, sin(view_angle)*1000, 1000);glPopMatrix();


I think the code is pretty easy to understand. Shouldn't that work?
Mitchen Games
Yaw is your 'view_angle' and pitch is your 'sight'. As for your code sample, I'm not sure what that's supposed to do; it may be that you have some fundamental misconceptions about transformations and OpenGL functions (or maybe I'm missing something).

Have you tried that code? Does it work? I'm guessing not. Anyway, the answer to your question is in my previous post, but ask if there's any part of it that you need help with.
Never mind, thanks. I got it to work. I did everything right in my last post, except the first three parameters in my init method should have been posX, posY, posZ.
Mitchen Games

This topic is closed to new replies.

Advertisement