Unity 2022.2.20(DX11) Colliders randomly not working

Hi,

I have a very simple 2D project here.
There is a ball inside a maze where player will rotate the maze.

Both of the ball and maze has Rigidbody 2D and Colliders 2D.
Sometime when the maze rotates, the ball will breakthrough the maze wall (here I say the Colliders is not working).
Video here:

I have been trying to:

  • Tweek the Time in the Project Setting
  • Using Update(), FixedUpdate(), fixedDeltaTime,deltaTime
  • Changing the Collision Detection on both ball and maze

Nothing works. The ball still able to go beyond the wall. What I noticed is that this only happen when either the ball or the maze move/rotate with a high speed.

This is the code I use to rotate the maze:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MazeManager : MonoBehaviour
{
    public float rotateSpeed = 100.0f; //You will easily see the issue happen when set this to 800 or beyond
    private float playerInput;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void FixedUpdate()
    {
        playerInput = Input.GetAxis("Horizontal");
        transform.Rotate(Vector3.forward * Time.deltaTime * rotateSpeed * playerInput);
        //transform.Rotate(Vector3.forward * Time.fixedDeltaTime * rotateSpeed * playerInput);

    }
}

This is the code I use to handle the ball movement

using System.Collections;
using System.Collections.Generic;
using UnityEditor.UIElements;
using UnityEngine;

public class UserInputManager : MonoBehaviour
{

    public Rigidbody2D rb;
    public Collider2D col;
    public float jumpAmount = 200.0f;

    // Start is called before the first frame update
    void Start()
    {
      
    }

    // Update is called once per frame
    void Update()
    {
        //Can jump only when the Ball touching Maze
        if(col.IsTouchingLayers(LayerMask.GetMask("Maze")))
        {
            if (Input.GetKeyDown(KeyCode.Space))
                {
                    rb.AddForce(Vector2.up * jumpAmount, ForceMode2D.Impulse);
                }
        }
     
    }
}

Basically the ball only follow the gravity and able to jump when I pressed Spacebar.

I have been reading these:

But seems both thread is not concluded yet.

Is there anyone here know the workaround to fix the issue?

Note: I am not using CC(Character Controller) from Unity.

Solved this!!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MazeManager : MonoBehaviour
{
    // Start is called before the first frame update
    public float rotateSpeed = 100.0f;
    [Range(0, 100)]
    public float playerInput = 50;

    List<Rigidbody2D> rbList;

    void Start()
    {
        var childCount = transform.childCount;
        rbList = new List<Rigidbody2D>();
        for (var childIndex = 0; childIndex < childCount; childIndex++)
            rbList.Add(transform.GetChild(childIndex).GetComponent<Rigidbody2D>());
    }

    void FixedUpdate()
    {
        var rotationAngle = Time.deltaTime * rotateSpeed * playerInput;
        var rotationDelta = Quaternion.Euler(Vector3.forward * rotationAngle);

        rbList.ForEach(rb =>
        {
            var relativePosition = rb.position - (Vector2)transform.position;
            var rotatedRelativePosition = rotationDelta * relativePosition;
            var newPosition = transform.position + rotatedRelativePosition;

            rb.MovePosition(newPosition);
            rb.MoveRotation(rb.rotation + rotationAngle);
        });
    }

}

Set the Maze into Kinematic