How to make two ball collide together correctly?

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

I made a small example with two balls that should collide together and bounce.
Sometimes the balls stay stucked together before being bounced.
I made a video of this: https://youtu.be/xtobyDJlEsQ
And the code:

extends KinematicBody2D
export(Vector2) var velocity:Vector2=Vector2(500,0)
func _physics_process(delta):
    var collision_info=move_and_collide(velocity*delta)
    if collision_info:
        velocity=velocity.bounce(collision_info.normal)
:bust_in_silhouette: Reply From: kidscancode

That code works fine here. However, I can break it by scaling the bodies. If I set the body’s scale to (1.1, 1.1) they “stick” before moving in a strange direction.

Collisions never work well with scaling. Keep your bodies at (1, 1) and scale the sprite and/or size the collision shape to match.

:bust_in_silhouette: Reply From: moechofe

I manage to fix it by increasing the Safe Margin of the of the KinematicBody2D.