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

Bug The Slime Critter attack throws the player several meters away

Discussion in 'Open Projects' started by Eddrico, Feb 3, 2021.

  1. Eddrico

    Eddrico

    Joined:
    Jan 29, 2021
    Posts:
    10
    Short description
    When the slime critter attacks and the player jumps, the inertia of the attack is transferred to the player, throwing the player several meters away.

    Expected behavior
    The attack should not push the player so far.

    To Reproduce
    Steps to reproduce the behavior:
    1. Open a scene with the TestingGround. Press play.
    2. Get near a Slime Critter and wait for his attack.
    3. When the attack is about to connect, press the jump button.
    4. Observe that the player is sent flying away.
    Notes
    • Here's a video of the issue:


    Ps.- Again, not sure if this is the right way to report a bug.
     
  2. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Hey, thanks for reporting it. Can you put it on the repository? (do you have a Github account?)
    Thanks again, QA is important too!!
     
  3. Eddrico

    Eddrico

    Joined:
    Jan 29, 2021
    Posts:
    10
    As a new issue right? done

    yes

    I was actually trying to identify the terrain with a raycast and i got stuck in the rocks, an accidental finding
     
  4. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
  5. Ehsan_74

    Ehsan_74

    Joined:
    May 20, 2016
    Posts:
    2
    Hi, I want to work on this bug, it is my first time to participate in an open project.I am so excited. I hope we can fix it.:);)
    It looks it is an important bug so i am on it, i hope i can do something.:oops:
    After finding the cause of the bug, i post my solution here.
     
    Last edited: Feb 22, 2021
    cirocontinisio likes this.
  6. asb9599

    asb9599

    Joined:
    Oct 22, 2017
    Posts:
    6
    Hi there! I posted this on the Discord, but I took a stab at this issue as well as another related one (#383) as part of a homework assignment I have for a course I'm taking. As far as the cause of the bug, it appears to be primarily due to the collider of the player and Slime being stuck inside each other after the hit logic is completed, which causes the player to be pushed back excessively. As far as the solution goes, I found that simply stopping the Slime after it successfully hit the player worked very well as an easy fix. However, I did end up adding a UnityEvent to the Attack class for ease of access to the Slime's particular attack logic during OnTriggerEnter, so I was not sure if this would be frowned upon by the community.
    Code (CSharp):
    1.     private void OnTriggerEnter(Collider other)
    2.     {
    3.         // Avoid friendly fire!
    4.         if (!other.CompareTag(gameObject.tag))
    5.         {
    6.             if (other.TryGetComponent(out Damageable damageableComp))
    7.             {
    8.                 if (!damageableComp.GetHit)
    9.                 {
    10.                     damageableComp.ReceiveAnAttack(_attackConfigSO.AttackStrength);
    11.                     // Invoke any necessary hit events
    12.                     onHit?.Invoke();
    13.                 }
    14.             }
    15.         }
    16.     }
    I also added a StopAttack() method to the SlimeCritterAttackController class that simply resets the timer used to update position in the target vector, so I simply hooked up that to the successful hit event and it appears to work properly now. Might need a bit more testing, but, given the damage logic of the game as it is right now I think that simply stopping the Slime after it hits the player is a good temporary solution.
     
    Amel-Unity and cirocontinisio like this.
  7. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Thanks @asb9599!

    @Amel-Unity this can be one trick to make the behaviour better! Still needs to be tested that it doesn't produce more edge cases...
     
  8. Amel-Unity

    Amel-Unity

    Unity Technologies

    Joined:
    Jan 30, 2020
    Posts:
    62
    Thanks @asb9599 for proposing this solution and opening the PR :)

    Just to clarify the status about the slime critter bugs:

    The bug discussed in this thread seems to be fixed and I asked last week in the GitHub issue if anyone is still able to reproduce it in the current version on the main branch? Then please make a video, otherwise I think we can close it (To avoid anyone spending time to fix an issue that doesn't exist anymore).

    However, the PR is still valid for the "Slime Critter pushes player on top of small rocks" issue opened also in relation to the slime critter behavior. We can evaluate this PR to fix it but I wanted to double check if everyone considers it an issue first? we discussed it with @cirocontinisio and we both thought that the current behavior can be expected too instead of the character remaining in place, or be pushed to sides.

    So what are your thoughts on this? An issue, or not an issue, that is the question :)
     
    cirocontinisio likes this.