Bullet Firing

Started by
18 comments, last by raptorstrike 19 years, 3 months ago
A²+B²=C² in a right-angled triangle. (Triangle with a 90 degree corner)
That's my own theorem.

So basically, that line is squarerooting the C², because A²+B² is put into the sqrt().
Advertisement
Quote:Original post by cornflake
Thanks for the example. One more idiot question - I understand the code except for the use of the * characters...

The * sign is multiplication.

In this instance

It's also used with pointers, but you'll get there, when you get there.
if(this.post == SATISFYING){money.send(1.00,&HemoGloben);return thanks;}
Original post by mikeman
struct CVector2D{float x,y};CVector bullet_pos,bullet_vel;CVector monster_pos,player_pos;void Normalize(CVector2D &v){float length;length=sqrt(v.x*v.x+v.y*v.y);v.x=v.x/length;v.y=v.y/length;}void FireBullet()//Called when you want to fire a bullet{CVector2D temp;temp.x=player_pos.x-monster_pos.x;temp.y=player_pos.y-monster_pos.y;Normalize(temp);bullet_vel.x=temp.x*5.0;//Just some constantbullet_vel.y=temp.y*5.0;}void MoveBullet(float dt){bullet_pos.x=bullet_pos.x+bullet_vel.x*dt;bullet_pos.y=bullet_pos.y+bullet_vel.y*dt;}


I don't think it's right that you dis other people for their answers. You're basically being arrogant, but hey, look what I found, mr. I-Know-It-Better? If length in Normalize() is 0, you're dividing to 0 also.

So please have a kind attitude if you're helping, but if you're showing off, go elsewhere.
Quote:
So please have a kind attitude if you're helping, but if you're showing off, go elsewhere.


You might want to take your own advice. Can you give me one example when I wasn't kind? I was just trying to show the OP what is IMO the most right way to do this, and if I remember correctly, you posted after I had posted my answer. And I posted the code because the OP himself said he wanted to look into vectors with more detail and asked what Normalize() meant.

Anyway, I don't really understand why you're offended, what is this, a pissing contest? Geez. And keep the "go elsewhere" comments to yourself. I don't have to answer to you about anything. Grow up a little, okay?

-PS: And if the length of the vector is 0, that means the player and the monster have the exact same position. Not going to happen if the game is correctly implemented.

[Edited by - mikeman on January 4, 2005 4:36:46 PM]
Don't worry mikeman, those of us with some sense can see that you were actually being very helpful. I think you were being quite nice. Some people can't take criticism well at all.

Pipo's replies were simply inadequate and thus not very helpful, lacking any explanation whatsoever. Bamboozling people with pythagoras theroem, without any explanation of how to apply it here, certainly counts as showing off in my book. His comments were certainly uncalled for, and he should know better!
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
Quote:Original post by mikeman
void Normalize(CVector2D &v)
{
float length;
length=sqrt(v.x*v.x+v.y*v.y);
v.x=v.x/length;
v.y=v.y/length;
}

You said that I was coding dangerously, but hey, I was using pseudo-code too! WOW!!
And look here, you're making the EXACT SAME mistake. But this time, it doesn't really look like it's pseudo-code, does it?


Quote:Original post by mikeman
And if the length of the vector is 0, that means the player and the monster have the exact same position. Not going to happen if the game is correctly implemented.

Well, you gave me a correct argument in this one, but I can just copy your argument in the case where I divided by zero. Errm.. ?
Quote:
Well, you gave me a correct argument in this one, but I can just copy your argument in the case where I divided by zero. Errm.. ?


Not really. You divide by (DifferenceX), which means divizion by zero will happen if the player is completely vertical with the monster. There's no reason why that can't happen in the game, in fact, it probably will happen. And I already gave a bunch of reasons on why working with vectors is better.

Pipo, what's wrong with you? I mean seriously. I pinpointed some drawbacks in the method you proposed to protect the OP from further problems. You act like it was a personal attack to you or something, and you turned this thread into a piece of crap, trying desperately to find errors in a method that nearly everyone uses, just to get back at me. And the only thing you accomplish is to confuse the OP even more with your ignorance. It's not like I invented vector math, I just know how to use them. If you don't, then you could benefit and learn from this thread. Instead, you're acting like a stupid 12yrold(unless you are indeed one).
Pipo DeClown, keep yourself civil and non-confrontational in this forum. I don't think I need to point out the consequences of ignoring a warning from me, and that goes for everyone. Don't take this thread off topic into a personal dispute. If you really are 6 years old, use email or PMs for your playground arguments.
So, cornflake wanted to find a way to compute a bullets path and then you two needed to jump into a pissing war. Beautiful! I didn't read the tutorial but if helped then good. I would have just computed slope and left it at that.
i agree with think all you have to do is compute the slope for example
  TempRect = MonsterRect  TempPlayerRect = PlayerRect    TempRect .y - TempPlayerRect .yM = ------------------------------ //this just means divided by but this is how you would code it    TempRect .x - TempPlayerRect .xif(bullet.x != TempPlayerRect .x  || bullet.y != TempPlayerRect .y){  bullet.x += 1  bullet.y = M* bullet.x}

the equation im going by here is Y= MX + B
this works without the B because were assuming the position of the monster to be the origin and there for there is no B and X just gose up by a constant rate unless you want the bullet to have a really funky curve so you would implement it like this. Im pretty sure my math is right here just let me know other wise
also the asignment of the rects in the begining is so that if either one moves the trajectory isnt screwed up (otherwise you would have an ever homming bullet i think ;)) make sure if you use this method that the TempRects are NOT updated every cycle make sure you only set them one when the bullet is fired
once the bullet has collided i would set the TempRects to -1 indicating that i can be used again

hope i helped
i figured this wasnt as complicated as vector math

[grin]
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie

This topic is closed to new replies.

Advertisement