RigidBody2D bounces when passing on top of two perfectly aligned StaticBody2Ds

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

When creating two StaticBody2Ds, no matter how well aligned they are, a RigidBody2D passing over them will jump upwards sometimes. I expected the RigidBody2D to just roll over the connection since there is no gap at all, but it jumps instead.

The video below shows the issue, with debug collision shapes visible:

video

Here’s the full code to reproduce; Just create a new project and attach the code to a Node2D:

extends Node2D

const STATIC_SIZE = 2000
onready var img = preload('res://icon.png')

func _ready():
	var rb := RigidBody2D.new()
	
	var s = Sprite.new()
	s.texture = img

	rb.add_child(s)

	# Add a circle shaped collision
	var rb_col := CollisionShape2D.new()
	rb_col.shape = CircleShape2D.new()
	rb_col.shape.radius = 50
	rb.add_child(rb_col)

	# Configure to have no friction and no damp
	rb.linear_damp = 0
	rb.physics_material_override = PhysicsMaterial.new()
	rb.physics_material_override.friction = 0
	
	# apply impulse
	rb.apply_impulse(Vector2.ZERO, Vector2(1050, 0))

	# follow with a camera
	var camera := Camera2D.new()
	camera.current = true
	rb.add_child(camera)

	add_child(rb)
	
	# create 10 consecutive StaticBody2D perfectly aligned
	var pos := Vector2(STATIC_SIZE / 2, 200)
	for x in range(0, 10):
		var ground := StaticBody2D.new()
		var ground_col := CollisionShape2D.new()
		ground_col.shape = RectangleShape2D.new()
		ground_col.shape.extents = Vector2(STATIC_SIZE / 2, 100)
		ground.add_child(ground_col)

		# Add a sprite so we can see where the division is
		s = Sprite.new()
		s.position = Vector2(-STATIC_SIZE/2, -50)
		s.texture = img
		ground.add_child(s)
	
		ground.position = pos
		add_child(ground)

		pos.x += STATIC_SIZE

I have tried with square shape and capsule shape, all of them present the issue

nosklo | 2019-04-26 04:34