Search Unity

Question Moving Plane Not Solid

Discussion in 'Editor & General Support' started by daniduckart, May 2, 2023.

  1. daniduckart

    daniduckart

    Joined:
    Feb 11, 2023
    Posts:
    11
    Hi All,

    So I know how to make a plane solid for general use. In this game I'm making the plane is the controller. You move the sphere (marble) around by tilting the plane. It's like an old labyrinth game.

    The problem I'm facing is when I tilt the plane one way, and then the opposite way the marble goes through the plane as though the plane isn't there. The sphere has a mesh collider and a Rigidbody, and so does the plane. I've tried changing the settings in the Ridgidbody and colliders and nothing seems to change. The colliders all seem to be the right dimentions. If I lower the rotation speed it happens less often, but even then the marble will eventually go through the floor.

    Any idea how to fix this either through settings or code?
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,859
    The sphere should probably have a sphere collider.

    Also make sure you are only manipulating the plane via the rigidbody API. Ergo, Rigidbody.MovePosition/Rotation. Moving it via the normal transform API will circumvent all physics.
     
  3. daniduckart

    daniduckart

    Joined:
    Feb 11, 2023
    Posts:
    11
    Oh yes the sphere has a sphere collider. So it needs to be updated in the code? I'll see if I can figure that out then.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    If you are moving the platform:

    - it MUST have an non-kinematic simulated Rigidbody

    - you MUST use the MovePosition / MoveRotation methods on it

    Here's why:

    With Physics (or Physics2D), never manipulate the Transform directly. If you manipulate the Transform directly, you are bypassing the physics system and you can reasonably expect glitching and missed collisions and other physics mayhem.

    This means you may not change transform.position, transform.rotation, you may not call transform.Translate(), transform.Rotate() or other such methods, and also transform.localScale is off limits. You also cannot set rigidbody.position or rigidbody.rotation directly. These ALL bypass physics.

    Always use the .MovePosition() and .MoveRotation() methods on the Rigidbody (or Rigidbody2D) instance in order to move or rotate things. Doing this keeps the physics system informed about what is going on.

    https://forum.unity.com/threads/col...-unity-physic-rigidbody.1216875/#post-7763061

    https://forum.unity.com/threads/oncollisionenter2d-not-being-called.1266563/#post-8044121
     
  5. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,635
    In addition to what everyone else said, I would probably try using a box collider for your plane, instead of the default mesh collider. I think that would work more reliably for a moving object.
     
    Kurt-Dekker likes this.