I am making a little rolling ball game, and I have a good movement system, but there is one problem with it. The way it works is pretty much, which ever way I am looking, I can use the WASD keys to move relative to that direction. But, it also works for up and down. I only want the movement force to be applied to the X and Z axis. How do I get it to NOT work for the Y axis. To be clear, I still want to be able to move on the Y axis, I just don’t want THIS movement system to move me on the Y. I am still VERY new to programming, so any help would be appreciated. Here is my movement script.
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float speed;
public GameObject center;
private Rigidbody centerRig;
void Start()
{
centerRig = GetComponent<Rigidbody>();
}
void Update () {
if (Input.GetKey(KeyCode.W))
{
centerRig.AddForce(center.transform.forward * speed);
}
if (Input.GetKey(KeyCode.S))
{
centerRig.AddForce(center.transform.forward * -speed);
}
if (Input.GetKey(KeyCode.D))
{
centerRig.AddForce(center.transform.right * speed);
}
if (Input.GetKey(KeyCode.A))
{
centerRig.AddForce(center.transform.right * -speed);
}
}
}