not move

HI
I created this code:

public class Hand : MonoBehaviour 
{
	public int speed;
	public Vector3 worldPos;
	public float mouseX;
	public float mouseY;
	public GameObject hand;

	void Update()
	{
		mouseX = Input.mousePosition.x;
		mouseY = Input.mousePosition.y;
		worldPos = Camera.main.ScreenToWorldPoint(new Vector3(mouseX, mouseY, 0));
		Vector3 lookDir = new Vector3(worldPos.x,worldPos.y, worldPos.z);
		hand.transform.LookAt(lookDir*speed*Time.deltaTime);
	}
}

I try to translate it from here:Top Down Shooter (Object Look At Mouse)
but because my game its a 2d I try to translate it with a little changes,half of the code works
in the inspector I can see that it takes the x and the y positions,but the problem is
that the hand is not rotating at all,and I dont know why,may be I should make the rotation on the z axis?
thx for the help:smile:

First of all you shoul be sure that speed is not 0

Second don’t declare internal fields as public, and use [SerializeField] attribute to show them in InspectorPanel.

	[SerializeField]
    private int speed;
	[SerializeField]
    private GameObject hand;
	
    private Vector3 worldPos;
    private float mouseX;
    private float mouseY;

And third fix these lines if you want to rotate hand along Y-axis (for 2D games):

worldPos = Camera.main.ScreenToWorldPoint(new Vector3(mouseX, 0, mouseY));
Vector3 lookDir = new Vector3(worldPos.x,worldPos.y, 0);

Good luck! :wink: