Jump to content
  • Advertisement
Sign in to follow this  
Megafox

Shooting Bullet Please Help!

This topic is 4697 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

Sigh. Ok I have started a little shooter project nothing fancy. I have just one bullet at the moment which when i press a key, moves using SDL. I do my target coords using my mouse, so i would have my "ship" as bullet origin and my mouse pointer as the bullet destination. I cant seem to make the bullet fly straight towards my destination. It has todo with my logic i think As I just check x and y and compensate accordingly. Do you guys have any suggestions ??

if (space_pressed)
	{		
		if (g_Bullet.screen_location.y < yBullet)
		{
			g_Bullet.screen_location.y += BULLET_SPEED;
		}
		
		if (g_Bullet.screen_location.y > yBullet)
		{
			g_Bullet.screen_location.y -= BULLET_SPEED;
		}

		if (g_Bullet.screen_location.x < xBullet)
		{
			g_Bullet.screen_location.x += BULLET_SPEED;
		}
		
		if (g_Bullet.screen_location.x > xBullet)
		{
			g_Bullet.screen_location.x -= BULLET_SPEED;
		}
}

Any help greatly appreciated!

Share this post


Link to post
Share on other sites
Advertisement
how about:

(see below!)

I think that's right, anyway. Haven't done it for a while

[Edited by - Kris_A on January 5, 2006 10:58:02 AM]

Share this post


Link to post
Share on other sites
Ill have a look thanks!

EDIT : You made one typo, and for the benefit of others fixed it up.


float angle = atan2(mouse.y - g_Bullet.screen_location.y, mouse.x - g_Bullet.screen_location.x);

g_Bullet.screen_location.x += cos(angle) * BULLET_SPEED;
g_Bullet.screen_location.y += sin(angle) * BULLET_SPEED;

Upping your rating.. thank you VERY much!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!