Get_contact_count() not returning anything when RigidBody2d collides with StaticBody2D

Godot Version

4.3

Question

I am trying to replicate the 2D Physics Platformer Demo from the RigidBody2D documentation.

I think I have everything matched. The RigidBody2d has a Sprite and a CollisionPolygon2D. The terrain is a StaticBody2D with a CollisionPolygon2D. When I enable Visible Collision Shapes I can see the collisions between the RigidBody2D and the StaticBody2D.

However, when I try to get the contact count in _integrate Forces of my RigidBody2D it never returns one so the loop is never entered.

func _integrate_forces(state: PhysicsDirectBodyState2D) -> void:
	var velocity := state.linear_velocity
	var delta := state.step

	var on_floor := false
	var floor_index := -1
	
	for contact_index in state.get_contact_count():
		print (contact_index)
		var collision_normal = state.get_contact_local_normal(contact_index)
		
		if collision_normal.dot(Vector2(0,-1)) > 0.6:
			on_floor = true
			floor_index = contact_index

Am I missing a config on one of the objects? I think I have them matched.

image

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