Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Rigidbody movement / physics issues during jumps

Discussion in 'Physics' started by CornParade, Feb 29, 2024.

  1. CornParade


    Feb 29, 2024
    I'm currently working on my movement and combat systems in my game. I want to make it so the following conditions apply:

    - When the player is grounded, the attack button triggers a regular attack.

    - When the player is jumping, the attack button triggers a jumping attack. This should stop them in midair while performing the attack before they start falling again.

    - If a player has performed a jumping attack, they cannot perform another jumping attack until they finish jumping and touch the ground again.

    I have most of this implemented without much trouble, but my issue is that odd physics behaviour occurs when I press both the jump and attack buttons at the same time while the player is grounded.

    - This causes the player to jump higher than they do when the jump button is pressed on its own. This happens both when jumping and attacking simultaneously in place, and when moving horizontally while jumping and attacking simultaneously.

    - It triggers the jumping attack animation at the same time that the player is jumping upward and doesn't stop them in midair, and they can still perform a jumping attack afterward. This second attack will behave as normal, preventing further jumping attacks and stopping the player in midair when it is performed. (From observation this occurrence appears to happen when the player is treated as grounded, so they may be performing a regular attack simultaneously with a jump and the animation is registering it as a jumping attack animation but not registering as an actual jumping attack.)

    I'm not fully certain what's causing this but I suspect it's either a quirk of the physics or an overlooked condition or the way the animations or triggers are set up. I suspect the issue may be in the block
    Code (CSharp):
    1. public override void Update()
    or the block
    Code (CSharp):
    1. public override void Attack()
    Links to the script files:

    Hero.cs - The player-specific jumping and attacking is largely defined here.

    Actor.cs - The hero class inherits from the actor class.

    InputHandler.cs - The attack and jump buttons are defined here.

    HeroCallback.cs - Interacts with Hero.cs, included in case it's relevant.

    HitForwarder.cs - Included in case it's relevant.
    Last edited: Mar 7, 2024