mirror of
https://github.com/minetest-mods/playeranim.git
synced 2025-04-15 16:30:40 +02:00
Work around wrong character bone rotations on Luanti 5.11+ (#6)
This commit is contained in:
parent
f763ce648e
commit
cabc79de36
25
init.lua
25
init.lua
@ -125,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)
|
||||||
@ -140,9 +151,17 @@ 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
|
||||||
player:set_bone_position(bone, position, rotation)
|
if player.set_bone_override then -- Luanti 5.9+
|
||||||
players_animation_data:set_bone_rotation(player, bone, rotation)
|
player:set_bone_override(bone, {
|
||||||
players_animation_data:set_bone_position(player, bone, position)
|
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)
|
||||||
|
players_animation_data:set_bone_rotation(player, bone, rotation)
|
||||||
|
players_animation_data:set_bone_position(player, bone, position)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user