Hi guys I have a code that doesn’t seem to be working for 3D I can move left and right but i cannot go forwards or backwards and my jumping is perfectly fine for my purpose. I would like you guys to look at the below script and let me know.
using UnityEngine;
using System.Collections;
public class PlayerMove: MonoBehaviour {
public float speed = 5f;
public float jumpSpeed = 8f;
private float movement = 0f;
private Rigidbody rigidBody;
private float move = 0f;
// Use this for initialization
void Start () {
rigidBody = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update () {
movement = Input.GetAxis ("Horizontal");
move = Input.GetAxis ("Vertical");
if (movement > 0f) {
rigidBody.velocity = new Vector2 (movement * speed, rigidBody.velocity.y);
}
else if (movement < 0f) {
rigidBody.velocity = new Vector2 (movement * speed, rigidBody.velocity.y);
}
if (move > 0f) {
rigidBody.velocity = new Vector2 (move * speed, rigidBody.velocity.z);
}
else if (move < 0f) {
rigidBody.velocity = new Vector2 (move * speed, rigidBody.velocity.z);
}
if(Input.GetButtonDown ("Jump")){
rigidBody.velocity = new Vector2(rigidBody.velocity.x,jumpSpeed);
}
}
}