Player doesn't turn

Hi there,

I’m using Unity tutorials to make a game and in this part - Survival Shooter Tutorial - 2 of 10 : Player Character - Unity Official Tutorials (new) - YouTube - I got issue because my player doesn’t turn there where my mouse is. Here is my code for turning:

    void Turning()
    {
        Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);

        RaycastHit floorHit;

        if(Physics.Raycast (camRay, out floorHit, camRayLenght, floorMask))
        {
            Vector3 playerToMouse = floorHit.point - transform.position;
            playerToMouse.y = 0f;
            Quaternion newRotation = Quaternion.LookRotation(playerToMouse);

            playerRigidbody.MoveRotation(newRotation);
        }
    }

I was trying to find issue on my own and everything I found as other people was fixing this is that they either didn’t have correct scale for quad which is floor - 100 x 100 x 1 - or they didn’t have Z scale at least 1, usually they had 0 or layer of quad which is floor was set up to defalut instead floor. I’ve had all of these setting already but my player still does not turn where my mouse it. Any ideas?

So we now know part of why it's not turning. This is called diagnostics. :) Now why doesn't it hit anything, we know the ray aims at the mouse pointer from the camera so make sure that the pointer is on the floor and if it still isn't looking at where the mouse pointer is then try moving the camera higher up and tilt it towards the character.

–

Difficult to tell from that picture, try moving the Camera so it's inside the room and looking down, at an angle, towards the player.

–

1 Answer

1

That part of your script looks fine but watch the last 5 minutes of that tutorial. They mention that Awake and FixedUpdate and some other functions get called automatically but other functions, that you create, don’t unless they’re called. I think you’re not calling

Turning();

In FixedUpdate or there’s a typo somewhere.

Hi again, move Q's like these to Help please if you choose to reply to them ;)

–