❔ I fly when I move forward
I am making a simple movement system but i am being forced in to the ground when I move back and I fly when I move forward this is the code
{
// creats rigidbody varyable called rb
Rigidbody rb;
// Start is called before the first frame update
void Start()
{
//shows what is in the rigidbody varyable
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
// jump script
{
if (Input.GetButtonDown("Jump"))
{
rb.velocity = new Vector3(rb.velocity.x, 5, rb.velocity.y);
}
// move forward script
if (Input.GetKey("w"))
{
rb.velocity = new Vector3(rb.velocity.x, rb.velocity.z, 5);
}
// move right script
if (Input.GetKey("d"))
{
rb.velocity = new Vector3(5, rb.velocity.z, rb.velocity.y);
}
// move backward script
if (Input.GetKey("s"))
{
rb.velocity = new Vector3(rb.velocity.x, rb.velocity.z, -5);
}
// move left script
if (Input.GetKey("a"))
{
GetComponent<Rigidbody>().velocity = new Vector3(-5, rb.velocity.z, rb.velocity.y);
}
}
}
3 Replies
sounds like you've got the y and z axes swapped
oh yes thanks for the help
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.