Why does not the object rotate to the cursor?why the code does not work?

Game in 3d. Rotate on 1 axis. I’m from Russia.`void Update () {

	var mous_pos = Input.mousePosition;
	mous_pos.y = 0;
	var tr = transform.position;
	tr.y = 0;
	var nap = Camera.main.ScreenToWorldPoint (mous_pos - tr);
	transform.rotation = Quaternion.LookRotation (nap);
}`

help me

Hi @pawel281

You’ll need to first get the input. Just like you do with the mouse_pos. This is screen position.

Next, you’ll have to transform your screen click position somehow to match something you see in camera viewport, and this can be done using Camera’s ScreenPointToRay method:

This will get you hit point in your terrain or ground plane, or whatever you have. Using ScreenToWorldPoint doesn’t do that.

Next you should probably do what you do in second last line, i.e. calculate direction towards this hit point from your player. Maybe also normalize it.

Then apply the rotation to your object.