#When I jump I can infinity jump.

1 messages · Page 1 of 1 (latest)

slim siren
#

You're modifying your vertical axis to go up. Make sure you account for gravity for that positive movement vector to be brought back down into the negative range to bring you back down.

frosty swan
#

Code and your current player inspector would help

slim siren
#

Of course 🙂

#
    private void FixedUpdate()
    {
        if (jumpKeyWasPressed)
        {
            GetComponent<Rigidbody>().AddForce(Vector3.up * 5, ForceMode.VelocityChange);
            jumpKeyWasPressed = false;
        }
        Movement();
    }
#

Right there you're accounting for going up. But how do you come back down?

#

Since you're using a Rigidbody, do you have a gravitational setting applied?

#

So you just keep repeatedly jumping?

#

On button press only, right? It doesn't loop jump without doing anything?

#

and you want a "cooldown"?

#

So the simplest way, although not necessarily the best is to keep track of when you can next jump

#

Oh you're still jumping when in the air?

#

Right so the is Grounded check is in place, let me take a further look

#

Are you getting valid debug logs with IsGrounded?

frosty swan
#

well as for me i want to ask you question what's the output of this code when you try to Jump?

    void OnCollisionStay(Collision collisionInfo)
    {
        if (collisionInfo.transform.tag == "Ground")
        {
            IsGrounded = true;
            Debug.Log("Grounded");
        }
        else
        {
            IsGrounded = false;
            Debug.Log("Not Grounded!");
        }
    }
slim siren
#

Since that's the focus point. If IsGrounded is true when you're in the air, that would be the cause

#

Just like @frosty swan mentioned. What's that Callback doing

frosty swan
#

if player was on the ground is it "Grounded"? and when player on the air is it still Grounded or Not Grounded?

slim siren
#

Is it ever "Not Grounded"? It should be like so when you're in the air

#

I think making sure you have "surface" below you before you can jump again would be the more appropriate approach of checking isGrounded

dark carbon
#

Is the ground jumping with you?

frosty swan
#

i think the problem is your collider somehow still detect the ground... even though player is in the air.

slim siren
#

Well the OnCollisionStay isn't going to trigger when you leave the ground, unless you're colliding with something else.

#

Try jumping into a wall, that's not marked as a Ground tag. Then you probably can't jump again.

dark carbon
#

@severe night are you jumping infinitely or just once after leaving the ground?

frosty swan
#

try OnCollisionEnter instead

dark carbon
#

Put that in

slim siren
#

Make sure it's not marked as "Ground". If you collide with it as well, you're going to have it trigger your onCollisionStay and override isGrounded to false. But in truth this is a confirmation that your grounded logic is flawed and should be reconsidered.

dark carbon
#

It prints the name of whatever you are colliding with

slim siren
#

A simpler solution would be to, on FixedUpdate, just before you decide whether or not to jump, is to make an isGrounded check yourself using a sphere collision check

#

I don't think onCollisionStay is going to do what you want.

#

That's for when you're staying in a collider. Like a "SUPERMAN AURA COLLIDER". As long as you stay in it you can make your character's head grow 3 inches per second 😛

frosty swan
#

in my knowladge if you have OnCollisionStay you should have OnCollisionExit (CMIIW)

dark carbon
#

Will give more info

#

The object is called Grounded?

#

Well then my code isn’t running

#

Well whatever it is, it is colliding with it

#

@severe night anyways, use OnCollisionEnter that sets you to grounded, and OnCollisionExit to set Grounded = false

frosty swan
#

AnyWhere where you want, but it's the best practice to put it right under OnCollisionStay ( Easy to read when others try to understand your code )

#

yep, and add this

if(collision.transform.tag == "Ground")
{
  IsGrounded = false;
}
#

tbh i rarely people uses this method and i haven't search it yet best use for OnCollisionStay/Exit

#

yep

dark carbon
#

Yes that works

#

Also why did you put my debug in the ungrounded part of we knew it wasn’t running

#

It’s fine but thought I’d point that out

frosty swan
#

or you could do something like this

void OnCollisionEnter(Collision other) 
{
  if(other.transform.tag == "Ground")
  {
    IsGrounded = true;
  }else
  {
    IsGrounded = false;
  }
}
#

well you don't know if you didn't try it out

#

i wound't tell you tho xD try it

dark carbon
slim siren
#

Just keep in mind if you're Entering another collision after having entered a ground collision, it can set your IsGrounded to false when it's still true.

frosty swan
#

tag is old one, and CompareTag is new one and efficient if im not wrong

slim siren
#

As I said, checking regularly for a surface below you through a Physics call it might be preferred.

#

You can make a simple GameObject within your player, move it down to the legs and do a Physics.SphereCheck upon that gameObject

#

This is to avoid facing issues further on when you end up with multiple collisions at once

#

As long as you have a ground below you, you should be able to jump

frosty swan
#

You welcome have a nice day!

slim siren
#

Ehh it's fine, just place it at the bottom part of your character that touches the ground

#

Just create child objects

frosty swan
#

depends on what games you are trying to makes

slim siren
frosty swan
#

its your rule not the player i think

slim siren
#

Physics.CheckSphere(footCollider.position, 0.5f);
As an example