Unify pod steering on lateral X tilt for flat and frontal holds.

Replace facing-only roll detection with atan2(x, yz) so left/right works in both orientations without a face gate.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-26 15:28:44 +02:00
co-authored by Cursor
parent 130532c4c9
commit 142968038c
3 changed files with 14 additions and 17 deletions
+8 -10
View File
@@ -60,18 +60,16 @@ func _process(_delta: float) -> void:
_pod.basis = _pod.basis.slerp(_target_basis, SMOOTH)
## Lenkrad-Roll in Radiant (links positiv). 0 wenn liegend oder in der Deadzone.
static func steer_roll(accel: Vector3, deadzone_rad: float = deg_to_rad(12.0)) -> float:
## Lateral tip in radians about device X.
## Positive = tip toward +X (works for flat left/right tilt and frontal wheel turn).
static func steer_roll(accel: Vector3, deadzone_rad: float = deg_to_rad(8.0)) -> float:
if accel.length() < MIN_ACCEL_LEN:
return 0.0
var n := accel.normalized()
var face_t := clampf(1.0 - maxf(n.z, 0.0), 0.0, 1.0)
if face_t < 0.25:
var angle := atan2(n.x, sqrt(n.y * n.y + n.z * n.z))
if absf(angle) <= deadzone_rad:
return 0.0
var roll := atan2(-n.x, -n.y)
if absf(roll) <= deadzone_rad:
return 0.0
return signf(roll) * (absf(roll) - deadzone_rad) * face_t
return signf(angle) * (absf(angle) - deadzone_rad)
func _basis_from_accel(accel: Vector3) -> Basis:
@@ -79,5 +77,5 @@ func _basis_from_accel(accel: Vector3) -> Basis:
# 0 = liegend (+Z), 1 = aufgerichtet / gedreht (wenig +Z)
var face_t := clampf(1.0 - maxf(n.z, 0.0), 0.0, 1.0)
var b := _basis_flat.slerp(_basis_facing, face_t)
var roll := atan2(-n.x, -n.y)
return Basis(Quaternion(Vector3.BACK, roll * face_t)) * b
var lateral := atan2(n.x, sqrt(n.y * n.y + n.z * n.z))
return Basis(Quaternion(Vector3.BACK, -lateral)) * b
+5 -6
View File
@@ -250,7 +250,7 @@ func _on_client_selection_changed(_idx: int) -> void:
setup_hint_label.text = "Links und rechts müssen verschiedene Pods sein."
else:
setup_hint_label.text = (
"Pod #%d links · Pod #%d rechts · frontal halten, Lenkrad drehen"
"Pod #%d links · Pod #%d rechts · kippen oder Lenkrad drehen"
% [_left_client_id, _right_client_id]
)
@@ -284,7 +284,7 @@ func _begin_playing() -> void:
_enable_both_streams()
_update_score_labels()
status_label.text = (
"Pod frontal halten · wie Lenkrad drehen · Tap = Boost (%ds)"
"Pod halten · links/rechts kippen oder Lenkrad · Tap = Boost (%ds)"
% int(BOOST_DURATION_SEC)
)
@@ -694,10 +694,9 @@ func _update_stars(delta: float) -> void:
func _effective_accel(side: int) -> float:
# Frontal halten, Lenkrad-Roll: links positiv → Schiff nach links (negativ).
# Lateral +X → Schiff nach rechts (flach kippen und frontal Lenkrad).
var a := _accel_for_side(side)
var roll := OrientationGizmo.steer_roll(Vector3(a))
return -roll * STEER_GAIN
return OrientationGizmo.steer_roll(Vector3(a)) * STEER_GAIN
func _velocity_scale(side: int) -> float:
@@ -734,7 +733,7 @@ func _update_connection_status() -> void:
match _socket.get_ready_state():
WebSocketPeer.STATE_OPEN:
status_label.text = (
"Frontal halten · Lenkrad drehen · Tap = Boost (%ds) · ♥×%d · CD %ds"
"Kippen / Lenkrad · Tap = Boost (%ds) · ♥×%d · CD %ds"
% [int(BOOST_DURATION_SEC), MAX_LIVES, int(BOOST_COOLDOWN_SEC)]
)
WebSocketPeer.STATE_CONNECTING: