Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to handle interiors of moving vehicles

Discussion in 'Physics' started by rapidrunner, Sep 21, 2020.

  1. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    Imagine I have a submarine or a boat; they move in world space, so I need a way to keep agents and player onboard, and let them enter inside closed areas.

    I read about how to accomplish this, and seems that there are 2 main approach: one is to make a convex volume from the mesh, and another is to place colliders on the surfaces you want the player or agents to walk on.

    I tried the convex route and the result is that it is quite problematic in small areas, with player and agents getting stuck; it works for a room size volume, but if you imagine a submarine room, that won't work at all.
    Tried to use colliders and that was somehow working, but incredibly time consuming, since for complex meshes you can't just add a cube and stretch it; otherwise the movements are hindered as much as in the convex approach.

    How do you deal with such scenario? Are there other ways to get this done reliably? I am looking for a solution that allow both player and agents to navigate the interiors and exteriors of moving objects.
     
  2. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    467
    If you want to use non-conves mesh colliders, they cannot be dynamic. That's a hard limit. You probably already know this, but you can split up your non-convex meshes into convex parts within your authoring software. It's beneficial to use a less detailed mesh for physics collisions anyways. But that's also a lot of extra work and maybe your non-convex visual mesh is already simple enough.

    In that case you might also get away with having a copy of the spaceship/moving vehicle somewhere else in the scene without a rigidbody, standing completely still and a copy of the player moving within it. You can use camera stacking to give the impression of the player actually interacting within the moving vehicle... but that's all really elaborate and doesn't "just work"