Hello! I’m working on a simple recreation of Pong Wars. I don’t think I’m doing anything unusual or weird in my collision handling code, but something weird happens after it runs for a few seconds where the balls get stuck:
Here’s my _physics_process. SPEED is currently hardcoded to 960. The outer wall is StaticBody2D with a CollisionPolygon2d with build_mode ofSegments.
func _physics_process(delta):
if not Engine.is_editor_hint():
var collision_info = move_and_collide(velocity * delta,false,0.62)
if collision_info:
DIRECTION = velocity.bounce(collision_info.get_normal()).normalized()
#if abs(DIRECTION.x) < .1: DIRECTION.x *=10
#if abs(DIRECTION.y) < .1: DIRECTION.y *=10
velocity = DIRECTION * SPEED
var collider = collision_info.get_collider()
if collider.is_in_group("blocks"):
collider.flip()
Does the problem also occur when you set safe_margin (in your move_and_collide call) to a lower or higher value? I had similar issues with CollisionPolygon2Din the past, so now I go the slightly more cumbersome route of creating one (relatively thick) rectangular CollisionShape2D for all four sides. Does that help?
At lower speeds, I was able to resolve those glitches by raising the safe_margin, but at 960 I seemed to have passed the threshold where that helps. Neither raising or lowering it seems that helpful.