So, I’m trying to use Input.GetKey() to add torque to my player object making him rotate when the arrow keys are pressed, like in the tutorial. But it’s not responding- I’ve tried using keycodes and just key names and also tried different keys, but it isn’t responding. I’ve also confirmed that the update is being called by using Debug.Log. I’m prepared to use a different method, but I’d like to understand what I’m doing wrong here in case it causes other issues. Thank you for any help!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerController : MonoBehaviour
{
[SerializeField] float torqueAmount = 1f;
Rigidbody2D rb2d;
// Start is called before the first frame update
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
if(Input.GetKey(KeyCode.LeftArrow))
{
rb2d.AddTorque(torqueAmount);
Debug.Log("left arrow key pressed");
}
else if(Input.GetKey(KeyCode.RightArrow))
{
rb2d.AddTorque(-torqueAmount);
}
}
}