Sign in to follow this  

Aiming with the mouse

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

This topic is 3581 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this