Bounce goes crazy

Godot Version

4.2.1

Question

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()
1 Like

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?

1 Like

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.

I’ll try the “4 walls” approach next .

Yep-- using four separate collision shapes worked just fine. Disappointing though, I was really hoping the single concave collision shape would work.

Yeah, it feels like a hack. :frowning: If anyone can share further details on why the concave shape doesn’t behave the same way here, I’d be very interested.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.