how can i make a object look at the mouse click only in the y axis?

With my code, the objecto look at the mouse click in all axis, and i justo want him to look at the y axis.

Here is my code.

> Blockquote

   public class lookat : MonoBehaviour {



private Vector3 mousePos;

void Update()
{
    if (Input.GetMouseButton(0))
        RotateToMouse();
}

void RotateToMouse()
{
    Vector3 vector = Input.mousePosition;
    vector.z = Mathf.Abs(Camera.main.transform.position.y - transform.position.y);
    vector = Camera.main.ScreenToWorldPoint(vector);
    transform.LookAt(vector);
}

}

@Caldas

I would think it would just be a matter of saving off the Vector of your original transform and setting the new vector appropriately. Sorry, bad explanation.

I also think you mean to store off your Mathf.Abs to vector.y don’t you?

void RotateToMouse()
 {
     Vector3 vector = Input.mousePosition;
     vector.y = Mathf.Abs(Camera.main.transform.position.y - transform.position.y);
     // originalVec is saved off when the head/position is moved (whatever).  
     // This is stored somewhere
     vector.x = originalVec.x;
     vector.z = originalVec.z;
     vector = Camera.main.ScreenToWorldPoint(vector);
     transform.LookAt(vector);
 }