So I am using cinemachine for my third-person camera and I got the camera movement part down, but if I move the camera the player doesn’t move in the way the camera is facing and that would make the character really hard to control if the player isn’t facing the way the camera. I don’t know where to start when it comes to stuff like this so help would be nice.
my playerMovement script:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BallController : MonoBehaviour
{
public float speed = 5f;
private Rigidbody rigid;
public float UpForce = 500f;
private bool isGrounded;
public Rigidbody rb;
public Transform cam;
private void Start()
{
rigid = gameObject.GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
if (Input.GetAxis("Vertical") < 0)
{
rigid.AddForce(-Vector3.left * speed);
}
else if (Input.GetAxis("Vertical") > 0)
{
rigid.AddForce(Vector3.left * speed);
}
if (Input.GetAxis("Horizontal") > 0)
{
rigid.AddForce(Vector3.forward * speed);
}
else if (Input.GetAxis("Horizontal") < 0)
{
rigid.AddForce(-Vector3.forward * speed);
}
if (rb.position.y < -1f)
{
FindObjectOfType<GameManager>().EndGame();
}
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && !isGrounded)
{
rigid.AddForce(Vector3.up * UpForce);
Debug.Log("Jumped");
isGrounded = true;
}
}
private void OnCollisionEnter(Collision other)
{
if (other.gameObject.CompareTag("Ground"))
{
isGrounded = false;
}
}
}