mirror of
https://github.com/minetest-mods/playeranim.git
synced 2025-07-16 15:20:37 +02:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
0b6bbe47e6 | |||
e293ee8ece | |||
bb7d0c3057 |
61
init.lua
61
init.lua
@ -22,17 +22,10 @@ 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
|
||||||
minetest.register_on_mods_loaded(function()
|
for _, v in pairs(player_api.registered_models["character.b3d"].animations) do
|
||||||
for _, model in pairs(player_api.registered_models) do
|
v.x = 0
|
||||||
if model.animations then
|
v.y = 0
|
||||||
for _, animation in pairs(model.animations) do
|
end
|
||||||
animation.x = 0
|
|
||||||
animation.y = 0
|
|
||||||
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)
|
||||||
@ -125,17 +118,6 @@ 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)
|
||||||
@ -151,17 +133,9 @@ 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_position(bone, position, rotation)
|
||||||
player:set_bone_override(bone, {
|
players_animation_data:set_bone_rotation(player, bone, rotation)
|
||||||
position = {vec = position, absolute = true},
|
players_animation_data:set_bone_position(player, bone, position)
|
||||||
rotation = {vec = rotation:apply(math.rad), absolute = true},
|
|
||||||
scale = {vec = bone_workaround_scales[bone], absolute = true},
|
|
||||||
})
|
|
||||||
else
|
|
||||||
player:set_bone_position(bone, position, rotation)
|
|
||||||
players_animation_data:set_bone_rotation(player, bone, rotation)
|
|
||||||
players_animation_data:set_bone_position(player, bone, position)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -280,14 +254,7 @@ 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()
|
||||||
-- Get the difference and normalize it to [-180,180) range.
|
return math_deg(player_yaw - body_yaw)
|
||||||
-- 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)()
|
||||||
@ -300,15 +267,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
local function animate_player(player, dtime)
|
local function animate_player(player, dtime)
|
||||||
local data = get_animation(player)
|
local animation = get_animation(player).animation
|
||||||
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
|
||||||
@ -357,3 +316,5 @@ minetest.register_globalstep(function(dtime)
|
|||||||
animate_player(player, dtime)
|
animate_player(player, dtime)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
minetest.log("action", "[playeranim] loaded.")
|
||||||
|
Reference in New Issue
Block a user