Dynamically Creating Obstacles and Collision Detection in Godot 4

I think it depends on what kind of objects you’re going to generate. If those obstacles are generic standalone objects, it’s entirely possible to create CollisionShape nodes on the go (I’m dealing with a similar situation, but my shapes are a bit more complex so I’m pre-generating them). For, say, a simple circle collision in 2D I’d do something like:

var circle = CircleShape2D.new()
circle.radius = 10.0 # probably your own variable here
var collision = CollisionShape2D.new()
collision.shape = circle
self.add_child(collision) #assuming this gets executed by your parent "obstacle"... it all really depends on your scene tree

Or rather, if there are dozens of similar instantiated rocks, I wouldn’t even create new Collision nodes each time, I’d just assign different shapes to a pre-created placeholder Collision.
From there on, collision detection is the same as with hand-placed CollisionShapes: you either make your “rocks” check for the character or vice versa.