Hello, all. I have been working on making my player character jump, and he jumps fine as long as he is not moving. If he is moving, however, ie I am pressing the keys to move him, he slowly ascends, seemingly ignoring gravity or the amount of force the Rigidbody added until I stop pressing the keys and he descends as desired. After I make him jump while idling, I can make him stay in the air by walking around, which is also undesirable. I don’t recall ever experiencing this before.
Here’s a section of the code so far.
public class PlayerScript : MonoBehaviour
{
public Animator Anim;
public Rigidbody RBody;
public float speed = 3f;
public float horizontalSpeed = 2.0f;
public float verticalSpeed = 2.0f;
public float jumpForce = 2.0f;
public Vector3 jump;
void Update()
{
float h = horizontalSpeed * Input.GetAxis("Mouse X");
transform.Rotate(0, h, 0);
transform.Translate(0, 0, speed * Input.GetAxis("Vertical") * Time.deltaTime);
Anim.SetFloat("speed", Input.GetAxis("Vertical"));
if (Input.GetKeyDown(KeyCode.Space))
{
Jump();
}
void Jump()
{
jump = new Vector3(0.0f, 2.0f, 0.0f);
RBody.AddForce(jump * jumpForce, ForceMode.Impulse);
}