player flicks when mouse is near the player

can anyone help me solve this problem

using UnityEngine;
using System.Collections;

public class Aim : MonoBehaviour {

public GameObject player;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
	Vector3 dir = Input.mousePosition - Camera.main.WorldToScreenPoint (transform.position);
	if (dir.x <= 90) {

		player.transform.localRotation = Quaternion.Euler (180,0,180);
	} else {
		player.transform.localRotation = Quaternion.Euler (0, 0, 0);
	}
	float angle = Mathf.Atan2 (dir.y, dir.x) * Mathf.Rad2Deg;
	transform.rotation = Quaternion.AngleAxis (angle, Vector3.forward);
}

}

You need to add a “dead zone” around the player. Something like this:

if (dir.x > 90 && dir.x < 100)
return;

but your code has more problems. You should be converting Input.mousePosition to worldspace coordinates otherwise you’re going to have very different values based on the screen size. This anser will help with that. Converting Mouse Position to World. Stationary Camera. - Questions & Answers - Unity Discussions