extends SceneTree const PROP_BLOCK_SCRIPT := preload("res://scripts/props/prop_block.gd") const PROP_STAGE_ROLES := preload("res://scripts/props/prop_stage_roles.gd") const RIG_SCENE := preload("res://scenes/characters/stickman/stickman_rig.tscn") var _failed: bool = false func _initialize() -> void: call_deferred("_run") func _run() -> void: var world := Node2D.new() root.add_child(world) var prop: PropBlock = PROP_BLOCK_SCRIPT.new() prop.position = Vector2(20.0, 0.0) prop.polygon_points = PackedVector2Array([ Vector2(-50.0, -150.0), Vector2(50.0, -150.0), Vector2(50.0, 150.0), Vector2(-50.0, 150.0), ]) world.add_child(prop) var rig: StickmanRig = RIG_SCENE.instantiate() as StickmanRig rig.position = Vector2.ZERO world.add_child(rig) await process_frame var roles: Dictionary = PROP_STAGE_ROLES.new_placement(false) roles["blocks_stickmen"] = true prop.set_stage_roles(roles) prop.apply_runtime_role(PROP_BLOCK_SCRIPT.RuntimeRole.START_STILL) await physics_frame await physics_frame rig.get_locomotion().sync_collision_bodies() var observed_hits: Array[PropBlock] = [] rig.get_locomotion().blocking_prop_sweep_hit.connect( func(hit_prop: PropBlock, _normal: Vector2, _position: Vector2, _velocity: Vector2) -> void: observed_hits.append(hit_prop) ) var into_prop: Dictionary = rig.get_locomotion()._sweep_actor_blocking_props(Vector2(20.0, 0.0)) _expect(is_equal_approx(float(into_prop.get("fraction", 1.0)), 0.0), "overlap blocks movement deeper into a stationary prop") _expect(not observed_hits.is_empty() and observed_hits[0] == prop, "overlap reports the struck prop") var out_of_prop: Dictionary = rig.get_locomotion()._sweep_actor_blocking_props(Vector2(-20.0, 0.0)) _expect(is_equal_approx(float(out_of_prop.get("fraction", 0.0)), 1.0), "overlap still allows movement away from the prop") rig.global_position = Vector2(-250.0, 0.0) rig.get_locomotion().sync_collision_bodies() await physics_frame await physics_frame var from_outside: Dictionary = rig.get_locomotion()._sweep_actor_blocking_props(Vector2(500.0, 0.0)) _expect(float(from_outside.get("fraction", 1.0)) < 0.999, "sweep still blocks when approaching a stationary prop from outside") world.queue_free() await process_frame if _failed: quit(1) else: print("PASS: actor blocking handles stationary props and initial overlaps") quit(0) func _expect(condition: bool, description: String) -> void: if condition: return _failed = true push_error("FAIL: %s" % description)