Hi there. I am a beginner programmer. I have a problem with Rigidbody.AddForce. I can get my cube to go fowards and backwards, but not sideways. Here is my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
//Refence to our Rigidbody
public Rigidbody rb;
//Reference to our ForwardForce
public float ForwardForce = 500f;
//Reference to our SidewaysForce
public float SidewaysForce = 500f;
void FixedUpdate()
{
//When "w" is pressed, we
//Add force along the Z-Axis
if (Input.GetKey(KeyCode.W))
{
rb.AddForce(0, 0, ForwardForce * Time.deltaTime);
}
//When "s" is pressed, we
//Add force along the -Z-Axis
if (Input.GetKey(KeyCode.S))
{
rb.AddForce(0, 0, -ForwardForce * Time.deltaTime);
}
//When "a" is pressed, we
//Add force along the X-Axis
if (Input.GetKey(KeyCode.A))
{
rb.AddForce(SidewaysForce * Time.deltaTime, 0, 0);
}
//When "d" is pressed, we
//Add force along the -X-Axis
if (Input.GetKey(KeyCode.A))
{
rb.AddForce(-SidewaysForce * Time.deltaTime, 0, 0);
}
}
}