Hi there! I’m currently facing a weird issue that I can’t seem to solve. Currently I am using cinemachine for my third person camera control, and I made a script that makes it so the character rotates at the time as the camera so his back should always be facing it.The problem is that, for some weird reason, he rotates properly, but he’s staying with it’s face towards the camera instead of it’s back.
Here’s the script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
Vector3 _CharacterDirection, realativedir;
Quaternion _CharacterRotation, rot;
Rigidbody _CharacterRigidbody;
[SerializeField]
float TurnSpeed = 8, speed = 6;
bool _IsWalking;
[SerializeField]
Camera VCam;
void Start()
{
_CharacterRigidbody = GetComponent<Rigidbody>();
}
void Update()
{
}
void FixedUpdate()
{
CharacterMovement();
}
void CharacterMovement()
{
//movement input's
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
_CharacterDirection.Set(h, 0, v);
// convert the character dir to cam dir
realativedir = VCam.transform.TransformDirection(_CharacterDirection);
realativedir.y = 0f;
realativedir.Normalize();
//change character forward to the desired one
Vector3 _DesiredForward = Vector3.RotateTowards(this.transform.forward, realativedir, TurnSpeed * Time.deltaTime, 0);
//_CharacterRotation = Quaternion.LookRotation(_DesiredForward); //use this for orbiting camera with no rotation in move
//rotate character with cam
rot = VCam.transform.rotation;
rot.x = 0;
rot.z = 0;
transform.rotation = rot;
//RigidBody Direction && Rotation
_CharacterRigidbody.MovePosition(_CharacterRigidbody.position + realativedir * speed * Time.deltaTime);
//_CharacterRigidbody.MoveRotation(rot);
}
}
I tried switching up a bunch of things in here but I just can’t seem to get this right.Should I re-import my model rotated 180 degrees?Would that fix it?Or is this just an issue that happens because of the script?
Here’s a photo of what happens in case what I said doesn’t make sense :
He should be facing the other way around, with his back at the camera, but this happens and I don’t understand what’s wrong.
I can’t seem to find the problem in here, so some help would really be appreciated!
Thank you!