Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Getting a sprite to rotate towards mouse?

$
0
0
Here is the code im trying..
// Get mouse input for rotation
		b2Vec2 mousePoint = b2Vec2(sf::Mouse::getPosition().x, sf::Mouse::getPosition().y);
		float deltaX = mousePoint.x - Body->GetPosition().x;
		float deltaY = mousePoint.y - Body->GetPosition().y;

		float desiredAngle = (-180/3.1415927) * atan2f( -deltaX, deltaY);

		// Set Rotation
		Body->SetTransform( Body->GetPosition(), desiredAngle );
		sprite.setRotation( Body->GetAngle());
		std::cout<<Body->GetAngle()<<std::endl;




It turns, but not correctly. It also never turns in a full circle, it just kind of swings. The values of Body->GetAngle() range from 180 to -180. I think what i want is the values to range from 0 to 360?

Anyways, how is this usually done?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>