- Home /
Question by
HappyPants84 · Jul 20, 2018 at 09:36 PM ·
movementrigidbodyjumpjumpingplayer movement
I need help with a movement script
hi, I'm very new to coding and I'm trying to make a movement script for my first game and the script was working fine until I tried to add a jump. the jumping didn't break the script but it does not work properly. could anyone please tell me how to make a jump script to this movement script:
[RequireComponent(typeof(Rigidbody))] public class PlayerMovement : MonoBehaviour {
public Rigidbody rb;
public float jumpHeight = 10000f;
public float walkingSpeed = 5f;
public float runningSpeed = 10f;
float speed;
void Start ()
{
rb = GetComponent<Rigidbody>();
speed = walkingSpeed;
}
void Update ()
{
if (Input.GetKey(KeyCode.LeftShift))
{
speed = runningSpeed;
}
else
{
speed = walkingSpeed;
}
float moveLR = Input.GetAxis("Horizontal") * speed;
float moveFB = Input.GetAxis("Vertical") * speed;
Vector3 movement = new Vector3(moveLR, 0, moveFB);
rb.velocity = movement;
}
}
Comment
Answer by madks13 · Jul 20, 2018 at 09:55 PM
There is a player controller script in the free assets provided by unity, you should look at it.
Your answer
Follow this Question
Related Questions
How to prevent player from moving in air while jumping in place?? 0 Answers
Player cannot jump 0 Answers
Simple Rigidbody2D movement and jump 0 Answers
Help with player movement and jumping 0 Answers