Search Unity

DOTS + Physics Body incorrect size?

Discussion in 'Physics' started by Siddown, Feb 12, 2020.

  1. Siddown

    Siddown

    Joined:
    Jun 13, 2013
    Posts:
    45
    I have been playing around with Unity DOTS and the new Physics preview. Since 2D isn't really available, I have been simulating 2D by using Quads, this has worked well so far. Attaching the Physics Body Component has allowed me to turn off the gravity and use the PhysicsVelocity component to move Entities around the screen.

    My only problem is collisions. If I have a prefab (say an Boulder) with a dimension x = 2 and y = 2, using the Linear Velocity fields of the Physics Body Component I can launch it at spawned Entities of the same prefab and a collision will occur (sending the other entities tumbling away). My issue is that it the collision only seems to occur at the very center of the Quad, so basically the two Entities are almost completely overlapping before the collision takes place (although not 100% overlapping, there does seem to be a bit of size to the physics body).

    When I use the Entity Inspector, I can't see anything that indicates the dimensions of the Physics Body is there something I'm missing?

    When I try and hit an entity that used a different prefab (say a Ship) which also has a Physics Body with the exact same settings, it misses entirely and no matter what I do they won't collide at all. Again, am I missing something here too? In the Entity Inspector both the Boulder and Ship have Physics Bodies and Physics Colliders.

    The two behaviors are inconsistent, and I just want to find a way to smash Boulders together or to have the boulder interact with the ship.

    Any thoughts would be much appreciated.
     
  2. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    I suspect you are trying to collide a bunch of co-planar quads edge to edge and they are just sliding past each other (possibly being pushed along the z-axis). If you make them boxes with some depth rather than flat quads this should not be a problem.

    I also recommend locking the inertia tensor so that they only rotate about the z axis or use a joint to limit movement and rotation. See this thread for details: https://forum.unity.com/threads/unity-physics-discussion.646486/page-7#post-4460308
     
  3. Siddown

    Siddown

    Joined:
    Jun 13, 2013
    Posts:
    45
    @steveeHavok you are 100% correct, I figured that out when I got back to it after a good night's sleep. I tried to play with the Movement system and to force every moving object to not rotate but it doesn't work all that well when collisions are taking place. I was about to try the "box" idea, so I'll let you know how it goes.

    I'll take a look at the Inertia Tensor as well.

    Thanks.
     
  4. Siddown

    Siddown

    Joined:
    Jun 13, 2013
    Posts:
    45
    @steveeHavok just a quick update, adding a larger Z-value to the Physics Shape solved the issue. The Job I have that cleans up the Z Velocity and X + Y rotation insures that everything stays on the same plane as well. That second thing is just a temp solution since I'm hoping that they make DOTS work with 2D objects down the road that will make this a much easier problem to solve.

    Thanks again!