Jump

with this script, if I hold down space the player continues to go up to infinity what can I put so that it goes up to a set height
thanks

   void Jump()
    {

        if (jumpInput>0 && Grounded())
         {
             velocity.y = moveSetting.jumpVel;
          }
         else if (jumpInput==0)
         {
             //zero out our velocity.y
             velocity.y = 0;
             if (transform.position.y > 0)
             {
                 Debug.Log("3funziona");
                 //decrease velocity.y
                 velocity.y -= physSetting.downAccel;
             }
      }

Could you post the code for the Grounded() function?

 bool Grounded()
    {
        return Physics.Raycast(transform.position, Vector3.down, moveSetting.distToGrounded, moveSetting.ground);
    }

I can’t draw any real conclusions from what you have there. I would assume that your Grounded function is always returning true. I would start checking the length of distToGrounded and the layers of the other objects your raycast could be interacting with.

I just checked and if transform.position.y> 6 and I repeat the bottom space y position doesn’t increase, but if I hold it down before it will
i don’t know why
the scene is empty there is only a cube

What is calling your Jump() function?

update

Might wanna start schprinkling in Debug.Log() calls to check:

  • is a particular piece of code even running?
  • what is the value of specific booleans, such as the result of Grounded()

Also, know that void update() will not be called. It has to be void Update()

Also, keep in mind Grounded() might be hitting the player or some part of the player and thinking "yup, I’m grounded. You can turn off the player’s collider during the Grounded() call, or else use layermasks to limit what Raycast can hit.

ALSO: Physics.Raycast() has about 57,000 overloads that mix and match parameters… you should used named arguments for the optional ones to make sure you’re not passing flags as a distance or distance as flags, for instance.