Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Incorrect rebound physics when quickly rotating object hits rigidbody

Discussion in 'Physics' started by ragleysenpai, Mar 31, 2023.

  1. ragleysenpai

    ragleysenpai

    Joined:
    Feb 2, 2023
    Posts:
    2
    Hi,
    I'm making a Foosball game utilizing ml-agents to actuate the rods, but I'm encountering some strange physics behavior. A demonstration of this strange behavior can be found here:
    . The ball seems to lose all momentum relatively often when the player swings around to hit the ball head on, as well as sometimes seeming to slide around the edge of the player foot.

    I've tried everything I can find to remedy these strange interactions. The time step is very low at 0.00833 for 120hz but I've also tried 0.01 and 0.005 to no avail. I've tried every combination of continuous collision detection on the ball and feet and none seems to make much difference. Current the ball is a rigidbody with continuous dynamic collision detection and a sphere collider. The feet use continuous speculative collision detection, but I've also tried the others and this seems marginally better. I've tried using both mesh colliders on the feet, as well as box colliders but both perform about the same. I've tried reducing the no-bounce threshold which helped a bit. The maximum angular velocity for all objects is very high to prevent any limitations. The contact pairs mode is set for all contact pairs. I've also increased the solver iterations for both default and velocity solvers to 12 and 4. I've also tried toggling auto-sync transforms, which didn't seem to help. I've lowered the bounce threshold because it seemed like it wasn't bouncing some times, and that seemed to help a bit. Max depenetration velocity is also greatly increased.

    The rods themselves are rigidbodies with kinematic foot components. The rods themselves are actuated using input from the neural network, using:

    Code (CSharp):
    1. allyAttackRod.AddForce(getRodVelLinear(0, allyAttackRod.transform.position.z, controlAttackForce.z), ForceMode.VelocityChange);
    2.                 allyAttackRod.AddTorque(getRodVelRot(allyAttackRod.transform.localRotation.z, controlAttackTorque.z), ForceMode.VelocityChange);
    3.                 allyMidfieldRod.AddForce(getRodVelLinear(1, allyMidfieldRod.transform.position.z, controlMidfieldForce.z), ForceMode.VelocityChange);
    4.                 allyMidfieldRod.AddTorque(getRodVelRot(allyMidfieldRod.transform.localRotation.z, controlMidfieldTorque.z), ForceMode.VelocityChange);          
    5.                 allyDefenceRod.AddForce(getRodVelLinear(2, allyDefenceRod.transform.position.z, controlDefenceForce.z), ForceMode.VelocityChange);
    6.                 allyDefenceRod.AddTorque(getRodVelRot(allyDefenceRod.transform.localRotation.z, controlDefenceTorque.z), ForceMode.VelocityChange);
    7.                 allyGoalkeeperRod.AddForce(getRodVelLinear(0, allyGoalkeeperRod.transform.position.z, controlGoalkeeperForce.z), ForceMode.VelocityChange);
    8.                 allyGoalkeeperRod.AddTorque(getRodVelRot(allyGoalkeeperRod.transform.localRotation.z, controlGoalkeeperTorque.z), ForceMode.VelocityChange);
    The function getRodVelRotation() and getRodVelLinear() simply gets the velocity the rod needs to travel at to get to a specific position in a decision interval. The ultimate goal of this project is to have a physical table the brain can be implemented on so the physics needs to be as accurate as possible at high speeds of rotation and translation for the rods. I appreciate any bit of advice anyone could provide, as I'm at a bit of a loss as to how to get this to work properly.