Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

InsanityX

Someone help me with this?

This topic is 6545 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!