- 物理规则:现行模型仅保留滚动阻力耗能与恢复系数碰撞,风力、空气阻力、静摩擦、动摩擦不再参与运行;确认三球质量 60/330/约890 kg 及水密度、流阻参数 - 定向加速改为真实顶面接触触发的一次性 +5 m/s 速度事件,模型新增渐进式 U 形导槽出口 - 更新球体、滑槽、水/冰/墙、球洞模型与 storybook 目录、物理、实体配置 - 工坊摆放、编辑器、运行适配与检查脚本同步;删除过时的 baseline 三组检查 - 新增谜题设计参考文档、关卡草稿与本轮实验产物
69 lines
3.2 KiB
GDScript
69 lines
3.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 = []
|
|
|
|
# Keep the solid cube under the guide. A vertical pick on the centreline can
|
|
# otherwise pass between the two mirrored triangle strips at some rotations.
|
|
static func guide_shape(mesh: Mesh, top: float) -> ConcavePolygonShape3D:
|
|
var faces := mesh.get_faces()
|
|
var raised := PackedVector3Array()
|
|
var cut := Plane(Vector3.DOWN,-top)
|
|
for i in range(0,faces.size(),3):
|
|
var triangle := faces.slice(i,i+3)
|
|
if maxf(triangle[0].y,maxf(triangle[1].y,triangle[2].y)) <= top+.00001:continue
|
|
var polygon := Geometry3D.clip_polygon(triangle,cut)
|
|
for j in range(1,polygon.size()-1):
|
|
raised.append(polygon[0])
|
|
raised.append(polygon[j])
|
|
raised.append(polygon[j+1])
|
|
var shape := ConcavePolygonShape3D.new()
|
|
shape.backface_collision = true
|
|
shape.set_faces(raised)
|
|
return shape
|
|
|
|
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")
|
|
var rise := float(block.get_meta("outlet_rise",0.0))
|
|
if normal.y < .9 or local.y < bounds.end.y-.025 or local.y > bounds.end.y+rise+.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")
|
|
var rise := float(block.get_meta("outlet_rise",0.0))
|
|
# The sphere can straddle the mouth after its centre leaves the tile.
|
|
var guide := AABB(Vector3(bounds.position.x,bounds.end.y,bounds.position.z),Vector3(bounds.size.x,rise,bounds.size.z))
|
|
if not guide.grow(radius+.025).has_point(local):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()})
|