ludic.character: the look goes up and down to 89 degrees (was -55..35), and the orbit's heading holds when the camera is straight over or under the pivot; ludic.aim: aim_ahead, whether a point is before the view

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-29 12:14:04 +03:00
parent 765d800842
commit 0b35f810b6
3 changed files with 21 additions and 2 deletions

View file

@ -13,3 +13,19 @@ export function aim_use(aim_st: AimState, kind: int) -> int {
if aim_st.am_kind == kind and aim_st.am_dist < AIM_USE_MAX { return AIM_USE_NOTHING }
return AIM_USE_NEAREST
}
# whether (x, z) is before the view: within `cos_min` of the camera's heading, seen from the body.
# Anything at the feet counts, where a heading means nothing, and so does all of it when the view
# looks straight up or down
const AIM_FEET: float = 1.2
export function aim_ahead(x: float, z: float, cos_min: float) -> bool {
let dx = x - AimView.body_x()
let dz = z - AimView.body_z()
let d = Math.sqrt(dx * dx + dz * dz)
if d < AIM_FEET { return true }
let fx = AimView.fx()
let fz = AimView.fz()
let f = Math.sqrt(fx * fx + fz * fz)
if f < 0.0001 { return true }
return (dx * fx + dz * fz) / (d * f) >= cos_min
}

View file

@ -44,7 +44,8 @@ export function char_camera_third(character_st: mut CharacterState, dt: float) -
character_st.chr_eye_z = cz
let ddx = ax - cx
let ddz = az - cz
character_st.chr_eye_yaw = Math.atan2(-ddx, -ddz)
# straight over or under the pivot the offset has no heading of its own: keep the look's
if ddx * ddx + ddz * ddz > 0.0025 { character_st.chr_eye_yaw = Math.atan2(-ddx, -ddz) } else { character_st.chr_eye_yaw = character_st.chr_cam_yaw }
character_st.chr_eye_pitch = Math.atan2(character_st.chr_piv_y - cyy, Math.sqrt(ddx * ddx + ddz * ddz))
}

View file

@ -55,7 +55,9 @@ function chr_gait(character_st: mut CharacterState, dist: float, dyaw: float, dp
}
}
# as far up and down as a view goes, a degree short of straight (where the heading would flip)
const CHR_PITCH_MAX: float = 1.553
function chr_look(character_st: mut CharacterState, dyaw: float, dpitch: float) -> void {
character_st.chr_cam_yaw = character_st.chr_cam_yaw + dyaw
character_st.chr_cam_pitch = Math.clamp(character_st.chr_cam_pitch + dpitch, -0.96, 0.61)
character_st.chr_cam_pitch = Math.clamp(character_st.chr_cam_pitch + dpitch, -CHR_PITCH_MAX, CHR_PITCH_MAX)
}