0
Q:

how to make an object point to mouse unity

Vector3 difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
        difference.Normalize();
        float rotation_z = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
        transform.rotation = Quaternion.Euler(0f, 0f, rotation_z + offset);
5
//Inside your update loop, add the following code:

//First, get the mouse position
Vector2 mousePosition = new Vector2 ( 
  Input.GetAxis("MouseX"), 
  Input.GetAxis("MouseY")
);
//Then, use unity's built-in lookAt function to do all the math for you:
transform.LookAt(mousePosition);
3
//Inside your update loop, add the following code:

//First, get the mouse position
Vector2 mousePosition = new Vector2 ( 
  Input.GetAxis("Mouse X"), 
  Input.GetAxis("Mouse Y"))
);
//Then, use unity's built-in lookAt function to do all the math for you:
transform.LookAt(mousePosition);
0

New to Communities?

Join the community