#### Archived

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

# Someone help me with this?

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

## 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 on other sites
Perhaps you should just use a fixed torpedo velocity, as this

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
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 on other sites
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 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 on other sites
Hey no worries. I love to help out

----------
Disco Love For Everyone

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 13
• 14
• 9
• ### Forum Statistics

• Total Topics
633366
• Total Posts
3011525
• ### Who's Online (See full list)

There are no registered users currently online

×