Why does car abruptly bounce when hitting the wall on rotation tween?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hydroper

When a car (RigidBody2D) collides with a wall (StaticBody2D) in state.angular_velocity != 0 and immediately moves to the opposite direction, an abrupt bounce occurs:

HTML5 demo:

The rotation tween occurs by mutating state.linear_velocity in _integrate_forces(state).

Car source:

To better describe the problem, the acceleration changes abruptly due to the rotation. The code in _integrate_forces mutating state.linear_velocity is just for applying max speed and deceleration.


For debugging purposes, I’ve tried this to lock the car to look at the up-left and disable the rotation tween when you move it:

func _ready() -> void:
    self._rotation_tween = ConstantPhysicsRotationTween.new(self, 5)
    self._camera.enabled = self.is_main_player
    self.rotation_degrees = TurnDirection.UP_LEFT.angle
    # self.rotation_degrees = self._turn_dir.angle

func _integrate_forces(state: PhysicsDirectBodyState2D) -> void:
    # self._rotation_tween.integrate_forces(state)

    # ...

So the problem is really the state.angular_velocity. How to solve this weird abrupt bouncing?