4 Commits

Author SHA1 Message Date
cabc79de36 Work around wrong character bone rotations on Luanti 5.11+ (#6) 2025-02-21 09:21:21 +01:00
f763ce648e Limit angle between head and body (#5)
Fixes head turning more than 90 degrees during minor lag, which appears unnatural.
2024-02-24 11:47:14 +01:00
e0acae8ed8 Workaround for Minetest #12189 2022-04-10 12:53:25 +02:00
9dab03f544 Clear up all animations of all registered models (#1)
Disable animations for all registered models, not only for "character.b3d".
Increases compatibility to other mods
2020-09-25 19:38:44 +02:00

View File

@ -22,10 +22,17 @@ end
-- stop player_api from messing stuff up (since 5.3) -- stop player_api from messing stuff up (since 5.3)
if minetest.global_exists("player_api") then if minetest.global_exists("player_api") then
for _, v in pairs(player_api.registered_models["character.b3d"].animations) do minetest.register_on_mods_loaded(function()
v.x = 0 for _, model in pairs(player_api.registered_models) do
v.y = 0 if model.animations then
for _, animation in pairs(model.animations) do
animation.x = 0
animation.y = 0
end end
end
end
end)
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
player:set_local_animation(nil, nil, nil, nil, 0) player:set_local_animation(nil, nil, nil, nil, 0)
end) end)
@ -118,6 +125,17 @@ minetest.register_on_joinplayer(function(player)
players_animation_data:init_player(player) players_animation_data:init_player(player)
end) end)
-- HACK work around https://github.com/luanti-org/luanti/issues/15692
-- Scales corresponding to default perfect 180° rotations in the character b3d model
local bone_workaround_scales = {
Body = vector.new(-1, 1, -1),
Arm_Left = vector.new(1, -1, -1),
Arm_Right = vector.new(1, -1, -1),
Leg_Left = vector.new(1, -1, -1),
Leg_Right = vector.new(1, -1, -1),
Cape = vector.new(1, -1, -1),
}
local vector_add, vector_equals = vector.add, vector.equals local vector_add, vector_equals = vector.add, vector.equals
local function rotate_bone(player, bone, rotation, position_optional) local function rotate_bone(player, bone, rotation, position_optional)
local previous_rotation = players_animation_data:get_bone_rotation(player, bone) local previous_rotation = players_animation_data:get_bone_rotation(player, bone)
@ -133,10 +151,18 @@ local function rotate_bone(player, bone, rotation, position_optional)
or not previous_position or not previous_position
or not vector_equals(rotation, previous_rotation) or not vector_equals(rotation, previous_rotation)
or not vector_equals(position, previous_position) then or not vector_equals(position, previous_position) then
if player.set_bone_override then -- Luanti 5.9+
player:set_bone_override(bone, {
position = {vec = position, absolute = true},
rotation = {vec = rotation:apply(math.rad), absolute = true},
scale = {vec = bone_workaround_scales[bone], absolute = true},
})
else
player:set_bone_position(bone, position, rotation) player:set_bone_position(bone, position, rotation)
players_animation_data:set_bone_rotation(player, bone, rotation) players_animation_data:set_bone_rotation(player, bone, rotation)
players_animation_data:set_bone_position(player, bone, position) players_animation_data:set_bone_position(player, bone, position)
end end
end
end end
-- Animation alias -- Animation alias
@ -254,7 +280,14 @@ local function rotate_body_and_head(player)
if #yaw_history > BODY_ROTATION_DELAY then if #yaw_history > BODY_ROTATION_DELAY then
local body_yaw = table_remove(yaw_history, 1) local body_yaw = table_remove(yaw_history, 1)
local player_yaw = player:get_look_horizontal() local player_yaw = player:get_look_horizontal()
return math_deg(player_yaw - body_yaw) -- Get the difference and normalize it to [-180,180) range.
-- This will give the shortest rotation between head and body angles.
local angle = ((player_yaw - body_yaw + 3.0*math_pi) % (2.0*math_pi)) - math_pi
-- Arbitrary limit of the head turn angle
local limit = math_pi*0.3 -- value from 0 to pi, less than 0.45*pi looks good
-- Clamp the value to the limit
angle = math.max(math.min(angle, limit), -limit)
return math_deg(angle)
end end
return 0 return 0
end)() end)()
@ -267,7 +300,15 @@ end
local function animate_player(player, dtime) local function animate_player(player, dtime)
local animation = get_animation(player).animation local data = get_animation(player)
if not data then
-- Minetest Engine workaround for 5.6.0-dev and older
-- minetest.register_globalstep may call to this function before the player is
-- initialized by minetest.register_on_joinplayer in player_api
return
end
local animation = data.animation
-- Yaw history -- Yaw history
if animation == "lay" or animation == "sit" then if animation == "lay" or animation == "sit" then