#Dev build of game has incorrect values

1 messages · Page 1 of 1 (latest)

keen forge
#

I don't know if that warning is relevant

#

There are no scripts that influence player jump height except for the script that actually makes the player jump

tender flax
#

Show that code

keen forge
#
public void jump(float j)
{
    Vector3 velocity = new Vector3(0f, jumpForce, 0f) + rb.velocity;

    if (isGrounded >= 0f && j>0)
    {
        rb.velocity = velocity;
        isGrounded = 0f;
    }
}

The jump function is handled by an external inputs script

keen forge
# tender flax Show that code
void Awake()
{
    if (playerControls == null)
    {
        playerControls = new PlayerInputActions();

        playerControls.Player.Verticality.performed += val => j = val.ReadValue<float>();//jump, walljump and DiveKick
    }

    playerControls.Enable();
}

void FixedUpdate()//Update function for physics based scripts
{
    MoveControl.jump(j);                                       //jump controls
}

This is the relevant part of that Input script

hollow iron
#

There are a few things you should adjust. First of all you probably don't want to add velocity to the current velocity. Because if you are currently falling, your jump will be weaker or just slow the fall a bit. Instead just assign a fixed value to the velocity like this: rb.velocity = new Vector3(rb.velocity.x, jumpForce, rb.velocity.z); That way you also keep your horizontal and z velocity. Secondly, never use Input related stuff in FixedUpdate. Your Input is always available in during the current Frame. So if your framrrate is 144 your Input might not be available is your fixedUpdate because that usually runs at 50 fps and won't even notice it. In your case it's not a problem, but for the wrong reasons. I suggest doing something like this:

#

PlayerInputActions _inputActions;

void Awake()
{

    _inputActions = new();
    _inputActions.Player.Enable();

    _inputActions.Player.Jump.performed += Jump_performed;
}

void OnDestroy()
{
    _inputActions.Player.Jump.performed -= Jump_performed;
}

void Jump_performed(InputAction.CallbackContext context) => OnJumpPerformed?.Invoke();
#

Now you can subscribe to the OnJumpPerformed Event like this: in Awake write: "InputClass".OnJumpPerformed+= jump; jump(){ if (isGrounded >= 0f)
{
rb.velocity = new Vector3(rb.velocity.x, jumpForce, rb.velocity.z);
isGrounded = 0f;
}

#

And don't forget to unsubscribe in OnDestroy. Do you know how events work?

keen forge
#

I’m sorry I meant to remove this post yesterday. I had accidentally been multiplying something in fixed update by delta time