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!