fix(vagrant): legs rotate to walk direction (user preference)
User feedback: 'Beine sollten in die richtung oszillieren, in die gegangen wird, nicht nach norden/süden relativ zum fenster.' Old: lower_control.rot = wedge_deg (substrate's body-relative ±30° sub-angle), legs always oscillated near world-up axis. New: lower_control.rot = atan(move_x, -move_y) = walk direction in sprite-top-up convention. Legs visually rotate to align with WASD direction → stride animation cycles along the walk axis. Side-effect: 4-direction-anim picker collapsed to single walk_fwd_lower (the rotation handles directional differentiation; 4 anims kept on disk for later gait-style work). Bumps puppet dep to 0.4.1 (head south-flick fix).
This commit is contained in:
29
init.lua
29
init.lua
@@ -71,11 +71,18 @@ local function pick_walk_anim(num_deg)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- HandleAnimationLower port: chooses walk anim based on signed angle between
|
-- Lower-body controller: legs rotate to walk direction (NOT Substrate's
|
||||||
-- body-forward and move-direction. Manages idle_lower / walk_* transitions.
|
-- body-relative wedge). User preference: leg stride visually aligns with
|
||||||
|
-- movement axis. lower_control.rot = atan(move_x, -move_y) so leg sprites
|
||||||
|
-- (which oscillate scl_y along their local Y) cycle along the walk axis.
|
||||||
|
-- One generic walk_fwd_lower anim suffices since the rotation handles
|
||||||
|
-- the directional change (4-direction anims kept on disk for future
|
||||||
|
-- gait-style differentiation).
|
||||||
local function update_lower_anim(moving, move_x, move_y)
|
local function update_lower_anim(moving, move_x, move_y)
|
||||||
if not moving then
|
if not moving then
|
||||||
-- Idle: stop all walk anims, resume idle_lower.
|
-- Idle: stop walk anims, resume idle_lower. Preserve last
|
||||||
|
-- lower_control_rot_deg so legs keep their last orientation
|
||||||
|
-- (no snap-back to north on stop).
|
||||||
if state.walk_anim_current ~= nil then
|
if state.walk_anim_current ~= nil then
|
||||||
for _, a in ipairs(WALK_ANIMS) do
|
for _, a in ipairs(WALK_ANIMS) do
|
||||||
puppet.stop(state.player, a)
|
puppet.stop(state.player, a)
|
||||||
@@ -91,22 +98,16 @@ local function update_lower_anim(moving, move_x, move_y)
|
|||||||
ci_last_state = "idle"
|
ci_last_state = "idle"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
state.lower_control_rot_deg = 0
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Walking: read body's previous-frame world.rot for signed angle computation.
|
-- Walking: legs face walk direction (sprite-top convention: rot=0 = -Y).
|
||||||
local _, _, body_rot = puppet.bone_world_transform(state.player, "body")
|
state.lower_control_rot_deg = math.deg(math.atan(move_x, -move_y))
|
||||||
-- Body forward direction (sprite-top-up convention): forward = -Y at rot=0.
|
|
||||||
-- In world coords: fwd_x = sin(rot), fwd_y = -cos(rot).
|
|
||||||
local fwd_x = math.sin(body_rot)
|
|
||||||
local fwd_y = -math.cos(body_rot)
|
|
||||||
local num = signed_angle_2d(fwd_x, fwd_y, move_x, move_y)
|
|
||||||
local anim_id, wedge_deg = pick_walk_anim(num)
|
|
||||||
state.lower_control_rot_deg = wedge_deg
|
|
||||||
|
|
||||||
|
-- Single generic walk anim (4-direction-picker deferred until we have
|
||||||
|
-- differentiated gait styles per direction).
|
||||||
|
local anim_id = "walk_fwd_lower"
|
||||||
if state.walk_anim_current ~= anim_id then
|
if state.walk_anim_current ~= anim_id then
|
||||||
-- Swap to new walk anim.
|
|
||||||
for _, a in ipairs(WALK_ANIMS) do
|
for _, a in ipairs(WALK_ANIMS) do
|
||||||
if a ~= anim_id then puppet.stop(state.player, a) end
|
if a ~= anim_id then puppet.stop(state.player, a) end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
{"id": "lib-core.camera", "version": "0.3.0"},
|
{"id": "lib-core.camera", "version": "0.3.0"},
|
||||||
{"id": "lib-core.render", "version": "0.1.0"},
|
{"id": "lib-core.render", "version": "0.1.0"},
|
||||||
{"id": "lib-core.maps", "version": "0.1.2"},
|
{"id": "lib-core.maps", "version": "0.1.2"},
|
||||||
{"id": "lib-core.puppet", "version": "0.4.0"},
|
{"id": "lib-core.puppet", "version": "0.4.1"},
|
||||||
{"id": "lib-asset.prototype-subterrain", "version": "0.1.1"}
|
{"id": "lib-asset.prototype-subterrain", "version": "0.1.1"}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user