Hello, I am trying to make my player stay the same speed when it jumps.
Right now it moves at the right speed but when I jump it starts to pick up much speed in the air. Is there a way to keep the speed constant while jumping?
using System;
using UnityEngine;
using System.Collections;
public class PlayerScript : MonoBehaviour
{
public float speed = 250f;
public float jspeed = 25f;
public bool jumpAllowed = true;
public bool jump = false;
private Rigidbody rb;
private int _pickupCount;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (Input.GetKeyDown (KeyCode.Space)) {
jump = true;
}
}
private void FixedUpdate() {
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed * Time.deltaTime);
if (jump == true) {
rb.AddForce(Vector3.up * jspeed);
jump = false;
}
}
}