Changing one GameObjects gravity

I have a character who jumps in my game, currently when he jumps, I set Physics.gravity to -25 so that he will fall to the ground faster but unfortunately, this affects every object in the scene.

Is there a way I can just affect the gravity of the character jumping? This is the code I’m using currently:

    //If the character is grounded, keep the gravity normal, otherwise, increase it
    if (isGrounded)
        Physics.gravity = new Vector3(0, -9.8f, 0);
        Physics.gravity = new Vector3(0, -25.0f, 0);

You can consume RigidBody.gravityScale property as well. Try like:

GetComponent<Rigidbody>().gravityScale = -0.55f;

Set this value as per your need.

I guess you don’t have the basis of physics.

What make you stand still on the earth and not go into the ground / fly into the air ? force compensation.

To make something be “less pushed” by a force, just add a force in the exact opposite direction with a certain “strength”.

But for your problem, you should consider applying a constant force to your object only. And, Unity provide a component called … Constant Force !

// C#
GetComponent<ConstantForce>().force = new Vector3(0, -25.0f, 0);

As mentioned above you can apply a constant force, though if all you’re looking to do is have a quick descent after reaching the jump’s peak…

Why not have a jumping state, possibly triggered by a GroundCheck collider (explained in the 2D Character Controller tutorial: though you may already have such a state check in place.

Then, while in that jumping state, you can monitor the rigidbody.velocity.y for when it reaches zero (the jump peak) and then apply a single downward force however you like.

[SerializeField] float downScaler = 5f;

void FixedUpdate()
    if(jumping && rigidbody.velocity.y < 0f) // still jumping and falling
        rigidbody.AddForce(Vector3.down * downScaler);