From f624d1fe36d6acfad22a1c0ad7542c059efd3234 Mon Sep 17 00:00:00 2001 From: LoneWolfHT Date: Tue, 22 Nov 2022 17:26:20 -0800 Subject: [PATCH] Add headanim --- mods/headanim/LICENSE | 21 +++++++++++++++++++++ mods/headanim/README.md | 7 +++++++ mods/headanim/init.lua | 21 +++++++++++++++++++++ mods/headanim/mod.conf | 2 ++ 4 files changed, 51 insertions(+) create mode 100644 mods/headanim/LICENSE create mode 100644 mods/headanim/README.md create mode 100644 mods/headanim/init.lua create mode 100644 mods/headanim/mod.conf diff --git a/mods/headanim/LICENSE b/mods/headanim/LICENSE new file mode 100644 index 0000000..670e2c8 --- /dev/null +++ b/mods/headanim/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020-2021 LoneWolfHT + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/mods/headanim/README.md b/mods/headanim/README.md new file mode 100644 index 0000000..1326210 --- /dev/null +++ b/mods/headanim/README.md @@ -0,0 +1,7 @@ +# Headanim +[![ContentDB](https://content.minetest.net/packages/Lone_Wolf/headanim/shields/downloads/)](https://content.minetest.net/packages/Lone_Wolf/headanim/) + +Makes player heads follow their look dir in Minetest. Requires version 5.3+ + +## Similar mods +* https://github.com/minetest-mods/playeranim: A lot more complex (and possibly slower?) than Headanim but looks nicer as a result diff --git a/mods/headanim/init.lua b/mods/headanim/init.lua new file mode 100644 index 0000000..36d0179 --- /dev/null +++ b/mods/headanim/init.lua @@ -0,0 +1,21 @@ +local get_connected_players = minetest.get_connected_players +local abs = math.abs +local deg = math.deg +local basepos = vector.new(0, 6.35, 0) +local lastdir = {} + +minetest.register_globalstep(function(dtime) + for _, player in pairs(get_connected_players()) do + local pname = player:get_player_name() + local ldeg = -deg(player:get_look_vertical()) + + if abs((lastdir[pname] or 0) - ldeg) > 4 then + lastdir[pname] = ldeg + player:set_bone_position("Head", basepos, {x = ldeg, y = 0, z = 0}) + end + end +end) + +minetest.register_on_leaveplayer(function(player) + lastdir[player:get_player_name()] = nil +end) diff --git a/mods/headanim/mod.conf b/mods/headanim/mod.conf new file mode 100644 index 0000000..70fa0a7 --- /dev/null +++ b/mods/headanim/mod.conf @@ -0,0 +1,2 @@ +name = headanim +min_minetest_version = 5.3