looking at mouse

Hey Guys I need a but of help ^^
I have a 3d top Down Game in perspectic view, and I need function to turn the mouse position into a position relativ of an Object, so my Player looks at the mouse.
Thanks for you Help in advance :smile:

You can use the prefab camera ā€œMultiPurposeCameraRigā€ in standard assets. Attach the following scripts (if not attached already):

  1. protect camera from wall clip
  2. auto cam
  3. free look cam

Then, create a new script with this code and attach to your character:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Mouse_move : MonoBehaviour {
    public Transform GameCamera;
    public Transform Character;
    private void Cam_Follow()
    {
        Character.eulerAngles = new Vector3(0.0f, GameCamera.eulerAngles.y, 0f);
        GameCamera.transform.position = new Vector3(Character.transform.position.x, Character.transform.position.y, Character.transform.position.z);

    }

    void Update () {
        Cam_Follow();
    }
}

Drag your camera and character to GameCamera and Character to the script in the inspector. If I understand your situation, this should work fine.

sorry, but I think, you mean something different ^^ I have a top down shooter, and my Character should look at the mouse, not the Camera ^^. I tried it with making an Object, that has the x and y from the mouse, but thats not accurate, because its world space, I just need a function to get the mouse position relativ to a gameobject