I want to have it tell me if I am falling thought a script I have ground check but I only want the gravity to change when you are falling so the jump doesn’t slow down thanks
If you’re using physics then you can just use the velocity.
Otherwise, just store the position in a variable at the end of the frame. then at the beginning of the next frame you can subtract the stored position from the current position. The result will be a direction vector in the direction that the object is moving.
public class AmIFalling : MonoBehaviour
{
Rigidbody rigidbody;
void Start()
{
rigidbody = GetComponent<Rigidbody>();
}
void Update()
{
if (rigidbody.velocity.y < -0.1f) // Can experiment with this value
{
Debug.Log("I am falling!");
}
}
}
I provided the code only for first request because I don’t exactly understand what you want here and why.
Rigidbody’s gravity is a constant value and it shouldn’t change whether you are grounded or in the air.
PS. Instead of removing gravity, can’t you just add more force when jumping?
Also make sure to use Impulse ForceMode, or similar:
rigidbody.AddForce(0, 0, 1, ForceMode.Impulse);