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