Hello! I am very new to coding so please forgive me. First off, in unity, the code is working just fine. No issues there. But, I am having a hard time understanding it. I get a bit lost when we start to use the rotationThisFrame parameter in the ApplyRotation method. I understand the value of the variable rotationThrust because it is defined at the beginning of the code (currently set to 1). But I am not quite sure where the value of rotationThisFrame comes from. Any assistance would be greatly apprecaited. Thanks!
This is what I have right now:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
Rigidbody rb;
[SerializeField] float mainThrust = 1f;
[SerializeField] float rotationThrust = 1f;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
ProcessInput();
ProcessRotation();
}
void ProcessInput()
{
if (Input.GetKey(KeyCode.Space))
{
rb.AddRelativeForce(Vector3.up * mainThrust * Time.deltaTime);
}
}
void ProcessRotation()
{
if (Input.GetKey(KeyCode.A))
{
ApplyRotation(rotationThrust);
}
else if (Input.GetKey(KeyCode.D))
{
ApplyRotation(-rotationThrust);
}
}
void ApplyRotation(float rotationThisFrame)
{
transform.Rotate(Vector3.forward * rotationThisFrame * Time.deltaTime);
}
}