Search Unity

Rigidbody and Triggers odd behavior.

Discussion in 'Physics' started by KomatsuMTS, Jun 20, 2017.

  1. KomatsuMTS

    KomatsuMTS

    Joined:
    Jul 18, 2016
    Posts:
    22
    Currently I have a Haul Truck that backs into a trigger. The trigger then animates an excavator to load the Haul Truck (no rocks). To make this realistic, I added rocks (with colliders) inside the bucket so the animation picks up the rocks (prepositioned in the bucket). Works great ""only"" if I start OnTriggerEnter with the Rigidbody (Haul Truck) as the rocks are caught by the mesh collider (bucket). Works GREAT... but..

    Problem is when I move the Haul Truck forward and start the scene. Then, back into the trigger. The rocks fall through the bucket. This poses many issues.

    I have tried using box colliders in the bucket, inflate mesh on rocks, used box, capsule etc to ensure they are caught in the bucket. Is this issue only seen by myself, or is there a way to get the rocks to be caught each time they are spawned in the bucket? Then, how to stop the rocks from popping out when transforming as the bucket swings. The rocks just seems to be lighter than air, even with 1000 Mass each and yes gravity is enabled.

    P.S. The rock prefabs are not a child of Haul Truck Rigidbody, or the Excavator.
    Have tried Mesh Collider --> Convex to bucket, Inflate, skin width same result. It has a failure percentage for me of 90%. Then, 10% it will catch 1 or two rocks of 15.
     
    Last edited: Jun 20, 2017
  2. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    412
    I don't quite follow which part is which from your description. Is the bucket the excavator scoop or the haul truck container?

    Do all your objects have rigid bodies?
    I think the truck and bucket should be kinematic. Your rocks not.

    You might have to switch your animators to use fixed update.
    You also may have to switch things back and forth between kinematic and not depending on which state they are in.
    Animated or simulated.
     
  3. KomatsuMTS

    KomatsuMTS

    Joined:
    Jul 18, 2016
    Posts:
    22
    Thanks for the reply. The video shows the examples. There is a small Java code for the animation to trigger OnTrigger. https://bcove.video/2sZUN1Q

    The Haul Truck is drivable, the Excav is not. Just static until animation.
     
  4. KomatsuMTS

    KomatsuMTS

    Joined:
    Jul 18, 2016
    Posts:
    22
    Here is the only code for the Loading Trigger.

    " var LoadTruck : Animation;



    function OnTriggerEnter(Other : Collider)
    {
    if(Other.gameObject.tag == "Player")
    {
    LoadTruck.Play("Loading");

    }
    }
    "
     
  5. KomatsuMTS

    KomatsuMTS

    Joined:
    Jul 18, 2016
    Posts:
    22
    I just checked the bucket. Since the boom is segmented and animated, there is no rigidbody on the bucket, only mesh colliders. If I add a rigidbody, it falls through terrain. The approach suggested breaks the physics.

    I tried kinematic for the Haul truck, then it does not move.
     
  6. KomatsuMTS

    KomatsuMTS

    Joined:
    Jul 18, 2016
    Posts:
    22
  7. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    412
    I think you need to research the physics sytem more so you understand the differences in rigid bodies (kinematic and non) and static colliders and when they should be used.

    Because what you described is not how the system is designed to be used.
    You also need to decide is this a simulation or you just want physics to add a little realism.

    This is important to know before designing your setup.
     
  8. KomatsuMTS

    KomatsuMTS

    Joined:
    Jul 18, 2016
    Posts:
    22
    The issue was not anything you mentioned. There was a gap in the MESH colliders, so when the rocks settled they fell into a small gap. Thanks for playing
     
  9. daxiongmao

    daxiongmao

    Joined:
    Feb 2, 2016
    Posts:
    412
    Trying to help people with a question isn't a game. Trying to guess the problem from limited information given by someone that doesn't know enough about their own problem.
    I gave you advice on common problems and when that didn't help asked you to better understand the systems involved.
    I'm sorry I wasn't able to read your mind to realize you had not checked a very obvious thing, like see if your collider meshes were valid.