# sit.ludic - sitting: on a seat's point, or on the ground where the body stands. The pose either # side is a still one, so the sit's own weight (body_sit_t) eases 0 -> 1 over a quarter second and # the body walks the last step to the seat over the same time rather than jumping there. # y is the seat's top and h how far above the feet it is, so the feet rest y - h (0 on the ground); # standing up leaves from the seat's own point unless char_sit_leave names another export function char_sit(character_st: mut CharacterState, x: float, y: float, z: float, yaw: float, mode: int, h: float) -> void { character_st.chr_sit = true character_st.chr_sit_mode = mode character_st.chr_speed = 0.0 character_st.chr_move = 0.0 character_st.chr_run = 0.0 character_st.chr_sit_x = x character_st.chr_sit_y = y character_st.chr_sit_z = z character_st.chr_sit_h = Math.max(h, 0.0) character_st.chr_sit_yaw = yaw character_st.chr_leave_x = x character_st.chr_leave_z = z character_st.chr_water = CharacterGround.water(character_st.chr_x, character_st.chr_z) } # where the body stands when it gets up out of this seat: in front of a bench, beside a boat's thwart export function char_sit_leave(character_st: mut CharacterState, x: float, z: float) -> void { character_st.chr_leave_x = x character_st.chr_leave_z = z } function chr_sit_tick(character_st: mut CharacterState, dt: float) -> void { var want = 0.0 if character_st.chr_sit { want = 1.0 } character_st.chr_sit_t = char_toward(character_st.chr_sit_t, want, 4.0 * dt) if not character_st.chr_sit { return } let k = Math.min(1.0, 8.0 * dt) character_st.chr_x = Math.lerp(character_st.chr_x, character_st.chr_sit_x, k) character_st.chr_z = Math.lerp(character_st.chr_z, character_st.chr_sit_z, k) character_st.chr_yaw = character_st.chr_yaw + char_wrap(character_st.chr_sit_yaw - character_st.chr_yaw) * k character_st.chr_y = Math.lerp(character_st.chr_y, character_st.chr_sit_y - character_st.chr_sit_h, k) character_st.chr_water = CharacterGround.water(character_st.chr_x, character_st.chr_z) } # Sitting down where the body stands: not astride something, not in the air, not on a slope, # not in the water. Asked again while sitting, it stands up. The answer is a CHAR_* for the game # to word. export function char_sit_here(character_st: mut CharacterState) -> int { if character_st.chr_sit { char_stand(character_st) return CHAR_STOOD } if CharacterBody.riding() { return CHAR_NOT_RIDING } if character_st.chr_air { return CHAR_NOT_AIRBORNE } if CharacterGround.slope(character_st.chr_x, character_st.chr_z) > 0.35 { return CHAR_NOT_STEEP } if character_st.chr_y < character_st.chr_water + 0.9 { return CHAR_NOT_WET } char_sit(character_st, character_st.chr_x, character_st.chr_y, character_st.chr_z, character_st.chr_yaw, CHAR_SIT_GROUND, 0.0) return CHAR_SAT } # standing up out of a seat put down against a boulder or a bank must not leave the body inside it export function char_stand(character_st: mut CharacterState) -> void { character_st.chr_sit = false let from_y = character_st.chr_y if char_safe_spot(character_st, character_st.chr_leave_x, character_st.chr_leave_z, from_y, 0.0) { character_st.chr_x = character_st.chr_safe_x character_st.chr_z = character_st.chr_safe_z character_st.chr_y = char_stand_at(character_st.chr_x, character_st.chr_z, from_y) } } # smoothstep, so a pose slows into the seat rather than arriving at full speed export function char_ease(t: float) -> float { let c = Math.clamp(t, 0.0, 1.0) return c * c * (3.0 - 2.0 * c) }