Advertisement

Someone help me with this?

Started by June 20, 2000 06:51 PM
3 comments, last by InsanityX 24 years, 6 months ago
Hey, I have a question concerning an asteroids type game. When the player fires i calculate the missile speed with Player_XVelocity added to a fixed missile velocity like this: // Compute Torpedo velocity vector float fTempXv = CosLookX[Wraith.m_iFacing] * TORPEDO_MAX_SPEED; float fTempYv = SinLookY[Wraith.m_iFacing] * TORPEDO_MAX_SPEED; float fOriginX = (Wraith.m_fWraithX + (Wraith.m_iWidth >> 1)); float fOriginY = (Wraith.m_fWraithY + (Wraith.m_iHeight >> 1)); FireTorpedo( fOriginX, // X coordinates fOriginY, // Y coordinates fTempXv+Wraith.m_fVelX, // Torpedo X velocity fTempYv+Wraith.m_fVelY); // Torpedo Y velocity It works sorta, but if im traveling in one direction and rotate to face the opposite direction while still traveling in the original direction (take breath) the missile travels very slowly.. Anyone whos made an asteroids type game have this problem? Or anyone else actually understand what im saying think they can help? I tried using the absolute value of m_fVelX, but that didnt work right either If you need to see more ill post it, i think thats about it though THANKS!
Perhaps you should just use a fixed torpedo velocity, as this
will avoid your problem.

To get the momentum of a ship to always speed up a torpedo, I
think you''ll have to take these steps...

1. Calculate the angle that the ship is TRAVELLING
2. Apply this angle to TORPEDO_MAX_SPEED
3. Add your ships velocity to torpedo velocity
4. Apply a 2d rotation to the torpedo velocity to
send it in the direction the ship is FACING.

this is a lot of work. I didn''t do it in my asteroids game


----------
Disco Love For Everyone
----------"i think that all this talking and such is paining my head to astounding annoyance" - Erick"Quoting people in your tag is cool. Quoting yourself is even cooler" - SpazBoy_the_MiteyDisco Love For Everyone
Advertisement
Y''know, I was just thinking about this last post over
dinner and I realised that the method I suggested
isn''t the only way. This would also work (i think):

1. Calculate the length of the ship''s vector

float ftmpval = sqrt((Wraith.m_fVelX*Wraith.m_fVelX)
+(Wraith.m_fVelY*Wraith.m_fVelY));

This just happens to be the ship''s current absolute speed.

2. Add on the torpedo speed

ftmpval = ftmpval + TORPEDO_MAX_SPEED;

3. Apply the angle that the ship is facing

float fTempXv = CosLookX[Wraith.m_iFacing] * ftmpval;
float fTempYv = SinLookY[Wraith.m_iFacing] * ftmpval;

There you go, you get the origin the same way as your original
code and you have enough info to call your torpedo function.

BTW: I still think a constant speed for torpedo fire is a better
model in gameplay terms.






----------
Disco Love For Everyone
----------"i think that all this talking and such is paining my head to astounding annoyance" - Erick"Quoting people in your tag is cool. Quoting yourself is even cooler" - SpazBoy_the_MiteyDisco Love For Everyone
Hey thanks, that i think thays just what i need. I tried the constant speed at first, maybe it''s just how i have it set up but depending on what speed the ship was moving and what way it was facing it would either bunch up all the shots or slow them to a crawl and some other little glitches.
You could probably get it to work but I cant

Thanks
Hey no worries. I love to help out


----------
Disco Love For Everyone
----------"i think that all this talking and such is paining my head to astounding annoyance" - Erick"Quoting people in your tag is cool. Quoting yourself is even cooler" - SpazBoy_the_MiteyDisco Love For Everyone

This topic is closed to new replies.

Advertisement