So I made my rocket look more like a ship/speeder and through this, it looks very awkward when I press A or D to rotate it. So I am thinking that instead of rotating it if I were to just move the ship forwards/backwards it would make the gameplay look more smooth.
Here is a picture of what my starship looks like:
Here is my code as of now, and it is working I just cannot figure out how to do a something transform.Rotate with position instead.
[SerializeField] float rotateSpeed = 1f;
[SerializeField] float thrustSpeed = 50f;
Rigidbody starshipRigidbody;
AudioSource starShipBooster;
// Start is called before the first frame update
void Start()
{
starshipRigidbody = GetComponent<Rigidbody>();
starShipBooster = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
// can thrust while rotating but cannot rotate both ways at once
ThrustStarShip();
RotateStarShip();
}
private void ThrustStarShip()
{
if (Input.GetKey(KeyCode.Space))
{
starshipRigidbody.AddRelativeForce(Vector3.up * thrustSpeed * Time.deltaTime);
if (!starShipBooster.isPlaying)
{
starShipBooster.Play();
}
}
else if (Input.GetKey(KeyCode.V))
{
starshipRigidbody.AddRelativeForce(Vector3.down * thrustSpeed * Time.deltaTime);
}
else
{
starShipBooster.Stop();
}
}
private void RotateStarShip()
{
float rotationThisFrame = rotateSpeed * Time.deltaTime;
// for manual control of rotation
starshipRigidbody.freezeRotation = true;
if (Input.GetKey(KeyCode.A))
{
transform.Rotate(Vector3.forward * rotationThisFrame);
}
else if (Input.GetKey(KeyCode.D))
{
transform.Rotate(-Vector3.forward * rotationThisFrame);
}
// enviroment control of rotation
starshipRigidbody.freezeRotation = false;
}