You'll need to access and store the Rigidbody component on our player capsule before modifying it:
- Update PlayerBehavior with the following changes:
public class PlayerBehavior : MonoBehaviour
{
public float moveSpeed = 10f;
public float rotateSpeed = 75f;
private float vInput;
private float hInput;
// 1
private Rigidbody _rb;
// 2
void Start()
{
// 3
_rb = GetComponent<Rigidbody>();
}
void Update()
{
vInput = Input.GetAxis("Vertical") * moveSpeed;
hInput = Input.GetAxis("Horizontal") * rotateSpeed;
/* 4
this.transform.Translate(Vector3.forward * vInput *
Time.deltaTime);
this.transform.Rotate(Vector3.up * hInput * Time.deltaTime);
*/
}
}
Here's a breakdown of the preceding code:
- Adds a private Rigidbody-type variable that will contain the capsule's Rigidbody component information...