Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Fast Moving Gameobject collision and trigger check failed

Discussion in 'Scripting' started by DreamerChaser, Nov 24, 2020.

  1. DreamerChaser

    DreamerChaser

    Joined:
    May 12, 2017
    Posts:
    12
    Hello guys
    I have a problem with collision detection via script check the video for more details
    Either when triggered or collided, the shell should be destroyed
    First shot -> the colliders are triggers, there is OnTriggerEnter Function on the colliders so it should be triggered but it didn't
    Second shot -> turn them into normal colliders and see if they worked, well they didn't again, but you can see, the shell bounces off the collider, so I know the collision "definitely" happened?
    Third shot -> Disable the right side collider, but keep the left side, still doesn't work
    do you have any ideas what is wrong? I got some idea on how Unity tries to simulate collision without even colliding first but it doesn't make sense at all since the OnCollisionEnter or OnTriggerEnter didnt work
    btw I am using Continious Dynamic and Interpolate for the tank and Extrapolate for the Shell, Well, i have used all the combos I could have used, I am not sure whether Rigidbody.SweepTest would work but just asking if there is any other solutions to it
    -Regards

     
  2. Terraya

    Terraya

    Joined:
    Mar 8, 2018
    Posts:
    646
    we would need to see any code from you,
    also have you Debugged information about whats happening in your code?
     
  3. DreamerChaser

    DreamerChaser

    Joined:
    May 12, 2017
    Posts:
    12
    Yes i did debug.log to see what's wrong but since it is not logging it is definitely wrong somewhere :(
     
  4. DreamerChaser

    DreamerChaser

    Joined:
    May 12, 2017
    Posts:
    12
    Armour.cs is attached to the collider on the tank, and Shell.cs is attached to the Shell itself, if you are wondering if I have set the tag correctly, yes I did, and I just double-checked it now and for sure, i did. Same goes with the layer masks. It is one thing if the shell passed through the collider but the shell gameobject literally got bounced so I cannot make sense why it doesn't get detected
    Armour.cs
    Code (CSharp):
    1.  private void OnCollisionEnter(Collision collision)
    2.     {
    3.         if (collision.gameObject.tag == "Shell")
    4.         {
    5.             Vector3 direction = -transform.forward;
    6.             if (armourSide == ArmourSide.Right)
    7.             {
    8.                 direction = -transform.right;
    9.             }
    10.             if (armourSide == ArmourSide.Back)
    11.             {
    12.                 direction = transform.forward;
    13.             }
    14.             if (armourSide == ArmourSide.Left)
    15.             {
    16.                 direction = transform.right;
    17.             }
    18.             collision.gameObject.GetComponent<ShellTest>().isHit(ArmourThickness, direction);
    19.             Debug.Log("Holy Shiet");
    20.         }
    21.     }
    Shell.cs

    Code (CSharp):
    1. private void OnCollisionEnter(Collision collision)
    2.     {
    3.         if (collision.gameObject.tag == "Untagged")
    4.         {
    5.             if (collision.gameObject.GetComponent<Armour>() != null)
    6.             {
    7.                 Vector3 direction = collision.gameObject.GetComponent<Armour>().direction;
    8.                 if (transform.GetComponent<PhotonView>().IsMine)
    9.                 {
    10.                     float Angle = Vector3.Angle(direction, Shell.velocity.normalized);
    11.                     Debug.Log(Angle);
    12.                     PhotonNetwork.Destroy(transform.gameObject);
    13.                 }
    14.             }
    15.         }
    16.     }
    Sorry for my bad english
     
  5. DreamerChaser

    DreamerChaser

    Joined:
    May 12, 2017
    Posts:
    12
    I also have tried with OnTriggerEnter by turning the colliders into Triggers but it still does not work. It is not debugging anything so i figure the method itself isn't being called, I mean it works sometimes but it doesn't work most of time since the shell is moving quite fast

    *I have both OnCollisionEnter and OnTriggerEnter in the Armour Script with the same code, the former one does not even work, while the latter one works but failed most of the time to detect the shell. The OnCollisionEnter in the Shell Script does not even work
     
    Last edited: Nov 24, 2020
  6. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,179
    If an object moves to fast, the default settings on Rigidbodies won't work. Those settings are the fastest performance wise, but breaks down when things moves at high velocities - generally velocities where they move at more than ~ half their size per frame.

    In particular, you'll want to change the "Collision Detection" mode to something different than "Discrete". See here.
     
    ali12000 likes this.
  7. mm_demon_developer

    mm_demon_developer

    Joined:
    Apr 2, 2020
    Posts:
    2
    Yes the Collision Detection Mode I am using is already Continuous Dynamic on both Gameobjects?
     
  8. mm_demon_developer

    mm_demon_developer

    Joined:
    Apr 2, 2020
    Posts:
    2
    But it still doesn't work
     
  9. JoshuaMcKenzie

    JoshuaMcKenzie

    Joined:
    Jun 20, 2015
    Posts:
    897
    Triggers do no interact with each other, at least one of them must be a collider. And in this case unless you want a mechanic where a single shell can penetrate multiple objects both should be colliders.

    Second thing is that in your OnCollisionEnter, place your debug logs outside the if blocks. it may very well be that the functions ARE calling but the if statements are evaluating to false.
     
  10. DeshanGunarathna

    DeshanGunarathna

    Joined:
    Jan 19, 2022
    Posts:
    16
    Have you find a solution to this problem? I have the same problem, no idea what to do. But in my case, only sometimes the trigger is not detected. Half of the time the triggering is detected.
     
    AverageWizard and ROBYER1 like this.
  11. AverageWizard

    AverageWizard

    Joined:
    Mar 11, 2019
    Posts:
    7
    Same issue. Fast moving object with a rigidbody and "continuous dynamic". Only sometimes triggers a trigger mesh collider.
     
  12. nathanaelkinnis

    nathanaelkinnis

    Joined:
    Sep 24, 2020
    Posts:
    4
    For anyone still struggling with collision for fast GO, check this vid out
     
  13. ali12000

    ali12000

    Joined:
    Sep 26, 2022
    Posts:
    2
    thanks ,very good