Collision is not working properly

I have two objects. The blue object has a Box Collider, and the red object has a Mesh Collider with Rigidbody.

The blue object works as follows:

void Update()
{
    if (direction == -1 && transform.position.z < -7.3)
    {
        direction = 1;
    } else if (direction == 1 && transform.position.z > -4.7)
    {
        direction = -1;
    }

    transform.position += new Vector3(0, 0, direction) * Time.deltaTime;
}

There is a video about the problem. After the red object falls, the blue object collides through the red object instead of pushing.

The Blue object has a Static Collider i.e. non-moving as it doesn’t have a Rigidbody.

You should be moving it Kinematically so add a Rigidbody, make it Kinematic and use MovePosition on it. Also, only do that in FixedUpdate because physics doesn’t run per-frame by default, it runs during the FixedUpdate cycle.

1 Like

Problem solved, thank you very much.

1 Like