3DTopdown - Player Rotate to Mouse

I’m working on a 3D topdown game. Where the player rotation to the mouse so he aiming where the mouse point.

I using this for the basic raycast and aim.

function Update() {
	var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
	var hit : RaycastHit;
	if (Physics.Raycast (ray, hit, 100)) {
		transform.rotation (ray.origin, hit.point);
	}
}

but it not really working the way i need it to work. It just making the player rotation everywhere.

PLZ HELP.

Try this:

 Vector3 mousePos = viewCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, viewCamera.transform.position.y));

        transform.LookAt(mousePos + Vector3.up * transform.position.y);

There are two things you need to make sure when using this script:

  1. Your camera is NOT parented to your child.
  2. You add Vector3.up * transform.position.y to your mouse position vector.

What is likely happening is your mouse is getting the world point of the GROUND. This means a line is being drawn between your character and the ground, making him rotate to face downwards.

Any slight movement of the mouse will rotate your character to look at the point but also rotate the camera super fast.

Adding Vector3.up adds an upwards vector to where you’re looking, then setting its magnitude (multiplying by transform.position.y) to your player’s character height means the character is looking straight ahead, perfectly parallel with flat ground he is standing on.

Orange: How your player is looking
Green: How you want your player to look.

And unparent the camera.