I am trying to get my player to rotate based on the direction of a Cinemachine Camera. I keep getting this error:
“Assets/Scriptd/PlayerController.cs(59,82): error CS0103: The name ‘rotationSpeed’ does not exist in the current context”
My code is below:
using UnityEngine;
using UnityEngine.InputSystem;
[RequireComponent(typeof(CharacterController), typeof(PlayerInput))]
public class PlayerController : MonoBehaviour
{
[SerializeField]
private float playerSpeed = 2.0f;
[SerializeField]
private float jumpHeight = 1.0f;
[SerializeField]
private float gravityValue = -9.81f;
[SerializeField]
private float rotationSpeed = .8f;
private CharacterController controller;
private PlayerInput playerInput;
private Vector3 playerVelocity;
private bool groundedPlayer;
private Transform cameraTransform;
private InputAction moveAction;
private InputAction jumpAction;
private void Start()
{
controller = GetComponent<CharacterController>();
playerInput = GetComponent<PlayerInput>();
cameraTransform = Camera.main.transform;
moveAction = playerInput.actions["Move"];
jumpAction = playerInput.actions["Jump"];
}
void Update()
{
groundedPlayer = controller.isGrounded;
if (groundedPlayer && playerVelocity.y < 0)
{
playerVelocity.y = 0f;
}
Vector2 input = moveAction.ReadValue<Vector2>();
Vector3 move = new Vector3(input.x, 0, input.y);
move = move.x * cameraTransform.right.normalized + move.z * cameraTransform.forward.normalized;
move.y = 0f;
controller.Move(move * Time.deltaTime * playerSpeed);
// Changes the height position of the player..
if (jumpAction.triggered && groundedPlayer)
{
playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
}
playerVelocity.y += gravityValue * Time.deltaTime;
controller.Move(playerVelocity * Time.deltaTime);
// Rotate towards camera direction.
Quaternion rotation = Quaternion.Euler(0, cameraTransform.eulerAngles.y, 0);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
}
}
Please Help!!!