• Advertisement
Sign in to follow this  

Aiming with the mouse

This topic is 3670 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
Sign in to follow this  

  • Advertisement