Rotate sprite

I want to shoot a rocket from my player to my current mouse position. But to do this I want to rotate the rocket to face my mouse cursor.
I’ve tried a lot of things now, but I can’t get it to rotate the right way. Anybody tried this before?

I am spending some time working on a solution for somebody who is trying to accomplish the same thing. I will post my results when I’m finished for you to use.

Thank you very much!! I’m looking forward to your solution:-)

I posted my solution here. Try it, maybe it helps you.

I guess Unitylover is referring to my thread here, as I have a similar problem.

I have googled this for some time now and everytime I find someone asking this question…no answers/solutions shows up.

This is a REALLY simple thing, or at least it should be, but apparent it’s not :slight_smile:

Hope Unitylover can point us in the right direction.

//Mads

Try something like this:

Vector3 rotation=Input.mousePosition - Camera.main.WorldToScreenPoint (transform.position);
		float angle=Mathf.Atan2(rotation.x,rotation.y)*Mathf.Rad2Deg;
		transform.rotation=Quaternion.Euler(new Vector3(0,0,angle-90));

you might have to change the 90 at the end, depending on your sprite.

Thanks for this snippet! You just solved in 3 lines of code what I’ve been trying to do all morning. I’m using this for a tank game and was trying to get the turret to rotate towards the mouse. To use your code for that purpose, the only change I had to make was to multiply the rotation.y by -1. Thank you again.

Thank you for that snippet, that helped me a lot!! I had to make some changes, but this really set me on the right path, thank you very much!!