I’m trying to expand a Roll-A-Ball game from the tutorial, and the first thing I wanted to do was add a controllable camera - achieved with Cinemachine - but the input still moves along the X and Z axis, not based on the camera’s look direction. Can anyone help? Here’s the PlayerController script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using TMPro;
public class PlayerController : MonoBehaviour
{
public float speed = 0;
public TextMeshProUGUI countText;
public GameObject winTextObject;
private Rigidbody rb;
private int Count;
private float movementX;
private float movementY;
[SerializeField] Transform Camera;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
Count = 0;
SetCountText();
winTextObject.SetActive(false);
}
void OnMove(InputValue movementValue)
{
Vector2 movementVector = movementValue.Get<Vector2>();
movementX = movementVector.x;
movementY = movementVector.y;
}
void SetCountText()
{
countText.text = "Dice: " + Count.ToString();
if(Count >= 12)
{
winTextObject.SetActive(true);
//Destroy Enemy
GameObject[] gos = GameObject.FindGameObjectsWithTag("Enemy");
foreach (GameObject go in gos)
Destroy(go);
}
}
void FixedUpdate()
{
Vector3 movement = new Vector3 (movementX, 0.0f, movementY);
rb.AddForce(movement * speed);
}
private void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Enemy"))
{
// Destroy the current object
Destroy(gameObject);
// Set the text to "You Lose!"
winTextObject.gameObject.SetActive(true);
winTextObject.GetComponent<TextMeshProUGUI>().text = "You Lose!";
}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("PickUp"))
{
other.gameObject.SetActive(false);
Count = Count + 1;
SetCountText();
}
}
}