So, I made a script that turns u when u use the a & d keys, and then u can go forward. But if u turn it doesn’t go in the new forward it goes in the original forward. How do I fix this?
(code)
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
//rb.AddForce(0, 0, forwardForce * Time.deltaTime);
//if (Input.GetKey("space"))
public class Movement : MonoBehaviour
{
public Rigidbody rb;
public float forwardForce = 1000f;
public float turnForce = 50f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKey("w"))
{
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
}
if (Input.GetKey("d"))
{
transform.Rotate(Vector3.right, turnForce * Time.deltaTime);
}
if (Input.GetKey("a"))
{
transform.Rotate(Vector3.right, -turnForce * Time.deltaTime);
}
}
}