Files
IntoHole/assets/blocks/directional_boost/behavior.gd
T
Yanchen 39ff1fd7b4 feat: 建立关卡工坊并整理项目目录
- 加入 Godot 基础试玩、画风展示和通孔验证场景
- 支持自由放球、多层叠放、墙壁、锥口球洞及固定 +5 m/s 定向加速方块
- 保存 Blender 源资产、模型导出、资源制作脚本和关卡编辑存档逻辑
- 按七类目录归档工程,集中 zsh 启动入口并补充 AGENTS.md 文件索引
- 同步设计规则、依赖锁定、验证报告和目录迁移记录

验证:目录迁移后的资源导入与四个场景加载通过;本次提交前检查暂存内容,未重复运行整套物理测试。
2026-11-16 11:12:21 +08:00

47 lines
2.2 KiB
GDScript

extends RefCounted
const KIND := "directional_boost"
const SPEED_GAIN := 5.0
# One latch per ball and block. A small separation margin tolerates contact jitter.
var active: Dictionary = {}
var events: Array = []
func integrate(state: PhysicsDirectBodyState3D, radius: float) -> void:
var touching: Dictionary = {}
for i in range(state.get_contact_count()):
var collider: Node = state.get_contact_collider_object(i)
if collider == null or collider.get_meta("piece_type", "") != KIND:continue
var block: Node = collider
while block != null and not block.has_meta("boost_bounds"):block = block.get_parent()
if block == null:continue
var contact: Vector3 = state.get_contact_collider_position(i)
var normal := (state.transform.origin - contact).normalized()
var local: Vector3 = block.to_local(contact)
var bounds: AABB = block.get_meta("boost_bounds")
if normal.y < .9 or absf(local.y - bounds.end.y) > .025:continue
touching[block.get_instance_id()] = block
for id in active.keys():
if touching.has(id):continue
var block = active[id]
if not is_instance_valid(block):active.erase(id);continue
var local: Vector3 = block.to_local(state.transform.origin)
var bounds: AABB = block.get_meta("boost_bounds")
if local.x < bounds.position.x-.025 or local.x > bounds.end.x+.025 or local.z < bounds.position.z-.025 or local.z > bounds.end.z+.025 or absf(local.y-bounds.end.y-radius) > .06:
active.erase(id)
# Stable order for the rare case of simultaneously touching two top faces.
var blocks: Array = touching.values()
blocks.sort_custom(func(a,b):return str(a.get_meta("record_id",a.name)) < str(b.get_meta("record_id",b.name)))
for block in blocks:
var id: int = block.get_instance_id()
if active.has(id):continue
active[id] = block
var before := state.linear_velocity
var direction: Vector3 = block.global_basis * Vector3(block.get_meta("boost_direction"))
direction.y = 0;direction = direction.normalized()
var speed := Vector2(before.x,before.z).length() + SPEED_GAIN
var after := direction * speed
after.y = before.y
state.linear_velocity = after
events.append({"blockId":str(block.get_meta("record_id",block.name)),"before":before,"after":after,"tick":Engine.get_physics_frames()})