How to move a rigidbody with a constant speed that does not lose gravity influence?

I’m trying to make a game where the player moves forward along the z axis constantly but also has the ability to jump around. The current code im using is letting the player move forward correctly but gravity is basically non existent. Why?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public Rigidbody rb;
    public float speed;

    void FixedUpdate ()
    {
        rb.velocity = new Vector3 (speed, 0, 0);
    }
}

You are manipulating the velocity of the rigidbody directly. The velocity of the rigibody include’s the effect gravity has on it. What you are doing is repeatedly replace the velocity on every fixed update, not allowing the rigidbody to accumulate the effect gravity is supposed to have on the rigidbody.

1 Like

Okay…? Can you tell me how to fix this?

There is very little incentive to give a solution when you yourself are not interested in understanding your own problem.

1 Like