Forum rules - please read before posting.

Collision issue with Movable objects

edited January 2017 in Technical Q&A
Hi all,

Can you help with the following issue?

We have a some corpse drawers in the scene and there are doors on the drawers and tables inside them. One of these drawers' door and table are Movable.
When we open the door and pull out the table than we can shut the door onto the table, because somehow they doesn't collide properly.

Screenshots:
image
image
We experience the above issue under the following versions under 64bit Windows 10:
  • Unity 5.6.0b4 with Adventure Creator v1.55b
  • Unity 5.5.0 with Adventure Creator v1.55b
  • Unity 5.5.0 with Adventure Creator v1.51f
Thank you for all of your assistance in advance!

Feel free to let me know if you need any further info, screenshot and or video about the mentioned issue we experience!
«1

Comments

  • As a last resort, you could disable the door while the table is out, but what of the components on the objects?  Do they have non-trigger colliders and Rigidbodies that cover their meshes?  The objects are still bound by the rules of Unity's own Physics system.


  • Yes they have rigidbodies and non-trigger colliders.
  • edited January 2017
    This is a Unity Physics issue.  You will need to ensure that both Draggables have their colliders on their root objects, i.e. the same place as their respective Rigidbodies.  Here's my attempt at something similar.
  • Well, it helps if I add a box collider to the table's root Draggable object, but I can still reproduce the issue in this case as well. It is harder to achieve the issue, but it is still possible.

    By the way the table's Draggable object has the Collosion Setting: Place children on same layer? enabled and it's sub object has a Convex Mesh Collider.

    In the attached attempt the rigidbodies are missing. Collosion working fine if I add at least a rigidbody component to one of the elements.
  • edited January 2017
    Rigidbodies need to be on both objects.  Were they not on the package I sent?  Something's gone wrong in the transfer if so.  Try the file again - I've updated it with removed prefab links.

    Again, this is a Unity Physics issue.  AC is not doing anything to hinder / help collisions between two objects, so any issue you have is down to Unity's implementation.  Documentation on Unity's site exists on how to improve physics performance, with tricks such as raising the "Solver Iteration Count" in the Physics settings.
  • Maybe your first attempt was better, but I imported as is, but not on top of AC. Now I imported it on top of AC, but I couldn't test the same thing in the setup, because I couldn't pull out the table enough. Somehow making the track longer doesn't works.

    Solver Iteration Count doesn't helps even with maximum value.
  • edited January 2017
    The two attempts were identical, the only difference were that there were no prefab links as you suggested they had no Rigidbodies, which they did.

    Try increasing the size of the colliders.  Again, if all else fails you could disable the door while the bed is open.
  • I see, but in the attempt the issue can't be tested, because the table couldn't be pulled out enough.

    It is a possible workaround, but not a good solution.
  • edited January 2017
    Collisions in unity are a b*tch. There are many things you need to take into account. Just to name a few:

    1. As mentioned, if you have two colliding objects, at least one of them has to have a Rigidbody for collisions to work. 

    2. Kinematic rigidbodies are usually meant to be static. If you move them manually they'll usually fail collision detection (I presume movement by animation counts here too). 

    3. If two objects have mesh colliders at least one needs to be Convex for collision detection to work.

    4. All nested trigger colliders need a rigid body of its own to be considered separate, else they are seen as part of the parent's trigger by any OnTrigger events in the parent (ie: All child trigger colliders will trigger the parent's OnTriggerEnter/Exit/Stay even if they are in separate GameObjects, but are children.) In this case you can put a rigid body on nested children' trigger colliders and set them to either kinematic or activate all constraints, that way they'll start working independently of each other.

    5. All colliders moved by changing the Transform.position or other methods like Translate() will also tend to ignore or fail collisions (you need to use forces instead, or manually calculate collision avoidance, etc).

    If you have very sensitive collision operations or collisions seem to be working generally bad in a project you can also try lowering the Time Step in Project Settings: Time. The lower the number the more accurate collisions will be (but with an increased overhead).
  • edited January 2017
    Of course, it isn't ideal.  I'm just offering alternatives - this is inherently a Unity issue.

    Couldn't be pulled out enough for what?  I was able to pull it out far enough for it to block the door.
  • Hi @Alverik, thank you for your comments!

    I know rule 1. and 3. and my set up is met with these rules.

    2. The rigidbodies in my set up are currently set to non-kinematic.

    4. I think the Place children on same layer? setting not working properly on the Moveable Drag object.

    5. I think the built in Moveable Drag script should handle this.

    I see. Luckily in other cases collosions are working fine. :)

    @ChrisIceBox I see.

    Yes, it couldn't be pulled out enough to test the issue. Maybe I am missing some steps during importing the mentioned attempt.
  • Do any of your models have children? Nested rigidbodies and colliders can also cause collisions issues, specially if the children use mesh colliders. Also, the Physics layer has nothing to do with #4, verifying that children have rigidbodies when it's necessary is something you have to do manually.
  • Going by your second screenshot, the issue is that opening the bed should prevent the door from closing, correct?  That is exactly what the scene I posted demonstrates - at least for me.  Perhaps you should try importing it into a separate project, after a fresh import of AC, so that you can be sure no other assets or settings are working against it.
  • @Alverik Currently yes. I have also tried using one object only without any child object, but it doesn't work as well.
    Currently the children have mesh colliders. They disappearing if I add a rigid body to them.

    @ChrisIceBox Yes, correct. I have exactly done that. Maybe the included demo files are causing this other issue, because I can see Tim Pot falling down in the scene after I start it.
  • edited February 2017
    They are disappearing if you add a rigid body to them? That means they're instantly falling through the world, ignoring collisions. There's definitely something wrong in there then. If you are ticking your objects as kinematic or turning on all constraints that should not be happening.

    Are the mesh colliders all convex? Does Unity ever throw any errors or warnings when you click on the Convex option or the istrigger option? verify by unticking and ticking the options back again. (There's geometry unity just can't turn into convex shapes and it'll report it.)

    Else try replacing the mesh colliders for one or multiple primitive shaped colliders (box, capsule, sphere, etc). Remember the same object can have multiple colliders, or trigger colliders, so just put enough colliders to roughly encompass the meshes' shape (remember you'll have to tweak each collider's shape manually to fit parts of the mesh). This is usually done a lot cause Mesh colliders are less performant than the primitive shaped colliders (strangely enough the sphere collider is suppposed to be the most performant of the primitive shaped ones. Capsule the least performant).

    You'll usually have lots of trouble using mesh colliders and/or children colliders (specially nested children/children under children), so try avoiding them whenever you can (if collisions matter). This is going to be specially true in AC when you use the Hotspot script directly on an object (and said object has child parts), cause you inevitably have to give the top level a collider to use it as a Hotspot. (Same thing has happened to me several times, like this one old key with a gem. The key and gem were separate meshes, and the parent was an empty with a hotspot, so the object just seemed to disappear if it had a rigidbody, but when I clicked the object in the herarchy during playmode, and watched the scene view, you could see the object was just falling at breakneck speed through the world). Whenever you can, ask your modeler to make the objects a single mesh, unless the part is intended to be animated, in which case is fine to have it as a separate object instead (again, if collision are a priority).
  • Your Rigidbody and Collider components should be on the root objects only.
  • Yes, they are convex. No, I am not getting any errors.

    I have already tried box colliders.

    Yes I know, but the issue still persist if I only  have a collider on the root object.
  • Actually, I think maybe the problem is with the Movable Drag script, because if I drag it gently and slowly then they collide properly, but if I do it too fast then they become entangled.
  • edited February 2017
    I can see how that appears so, but that's still Unity's physics behaviour at work.  When objects move very quickly - whether due to AC or not - if Unity is not calculating changes fast enough, things will go wrong.  This is why things like raising the Solver Iteration Count are necessary.  Other options in the Physics and Time tab should also be played with - there is much discussion on this on Unity's official forums.

    Settings on the Rigidbody components, such as Interpolate and Collision Detection, are also important factors.  I appreciate it can be very fiddly to get perfect behaviour, but again - this is Unity, not AC, at work.

    One option you can try on the Moveable Drag script, however, is to reduce the Max speed value.  This caps the maximum rate that an object can move, and can help prevent entanglement due to Unity's Physics system.
  • I have already tried adjusting those values. I tried again, but it doesn't help at all.

    I have already tried that even before submitting the issue here. Now I tried again, but it doesn't help.

    Of course it is a possible workaround, which works of course, but in this case, it is too hard to open the door.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.