Jump to content
  • Advertisement
Sign in to follow this  
Kr00pS

Aiming with the mouse

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

Hi! I'm making a 2D shooter game. I want to aim with the mouse so, I'm using this formula :
void Update()
{
	D3DXVECTOR2 vec_aim = Engine::GetInstance()->GetInputModule()->GetMousePosition();
	D3DXVECTOR2 vec_soldier = D3DXVECTOR2(GetPosition().x, GetPosition().y);

	m_Angle = atan((vec_aim.y - vec_soldier.y) / (vec_aim.x - vec_soldier.x));
}
But, there is a problem: it works only if the mouse abscissa coordinate are superior to the soldier abscissa coordinate. If not, the angle return to PI/2 or -PI/2 Click here to download the binaries Thanks for all.

Share this post


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