3rd person engine

hello everyone, I’ve been following this tutorial to try and make a 3rd person unity game,

but I’ve ran into a problem on the character rotation script:

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

public class thirdPersonCam : MonoBehaviour
{
    public Transform orientation;
    public Transform player;   
    public Transform playerObj;
    public Rigidbody rb;

    public float rotationSpeed;

    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
    }
    // Update is called once per frame
    void Update()
    {
        //rotate orientation
        Vector3 veiwDir = player.position - new Vector3(transform.position.x, player.position.y, transform.position.z);
        orientation.forward = veiwDir.normalized;

        //rotate player object
        float H = Input.GetAxis("Horizontal");
        float V = Input.GetAxis("Vertical");
        Vector3 inputDir = orientation.forward * V + orientation.right * H;

        if (inputDir != Vector3.zero)
        {
            playerObj.forward = Vector3.Slerp(playerObj.forward, inputDir.normalized, rotationSpeed);
        }
    }
}

the character isn’t pointing exactly in the right direction, it’s really strange and I have no idea how to fix it.
I push forward and sometimes the character goes forward but sometimes he goes sideways or even backwards. please someone help, thanks in advance!

Maybe check out a different Cinemachine specific 3rd person tutorial instead.

I watched this real quick and am baffled by the author commenting that the „settings are quite weird“, and then making so many adjustments without explaining any of them. This is a telltale sign that the author has no idea what he is doing! :frowning:

The resulting approach seems rather backwards, you don‘t make the player face in the direction of the camera. What if you switched to an observer or cutscene camera at some point? This would not work without unnecessarily complicating the code.

Instead one should move the player directly and independently of the camera. Then fix the camera to point in the same direction the target is facing, I believe this is part of Cinemachine setup and does not require programming.

1 Like

Please only post questions about the C# Job System in the C# Job System forum.

I’ll move your post to the Scripting forum for you.

Thanks.

1 Like

will try. thanks!

Sorry, kind of new to the whole unity forum thing and find it kind of hard to figure out what goes where and I’ll try to get it right next time.
Thanks!

No worries, just letting you know!

1 Like

Thanks!