so I have been trying to find this bug the whole day. I made a script that is supposed to look at the mouse position and then instantiate an arrow at an empty object which is rotated towards the cursor. However, it does work if the cursor is infront of the player but if it goes behind, it shoots and is rotated forward in the opposite direction the mouse is at. I tried many things like changing the y axis but they all mess it up. here is the script
#pragma strict
var mcursor : GameObject;
var mousePos;
var arrow_prefab : GameObject;
var angleBetween = 0.0;
var target : Transform;
var angle : float;
var emptytarget : GameObject;
var instan : GameObject;
var x : float;
function Start () {
}
function Update () {
mousePos = Input.mousePosition;
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
mcursor.transform.position = mousePos;
mcursor.transform.position.z = 0.0;
if(Input.GetMouseButtonDown(0)){
emptytarget.transform.LookAt(mcursor.transform.position);
emptytarget.transform.rotation.y = 0.0;
emptytarget.transform.rotation.x = 0.0;
if(mcursor.transform.position.x < transform.position.x){
}
else{
emptytarget.transform.rotation = emptytarget.transform.rotation;
}
instan = Instantiate (arrow_prefab, transform.position, emptytarget.transform.rotation);
}
}