I’m trying to make a cube move side to side, and I already have the forward movement which works fine. When I hit play, the cube goes forward, but it only manages to go side to side 3/10 times. My code is below. I am taking a course by brackeys to get started with unity. If any of you could help me, that would be welcome.
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public Rigidbody rb;
public float forwardForce = 2000f;
public float sidewaysForce = 500f;
// Start is called before the first frame update
// Update is called once per frame
void FixedUpdate()
{
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if ( Input.GetKey(KeyCode.D) )
{
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (Input.GetKey(KeyCode.A))
{
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange );
}
}
}