mirror of
https://github.com/luanti-org/minetest_game.git
synced 2025-05-21 06:43:17 -04:00
Player API: Animation-dependent collisionbox and eye_height
Backwards compatible with previous model definition format. For the Minetest Game player model, this avoids dead players having obstructive tall collision and selection boxes.
This commit is contained in:
parent
dd91a1bfe5
commit
fc86bf5a5f
3 changed files with 70 additions and 18 deletions
45
game_api.txt
45
game_api.txt
|
@ -476,15 +476,48 @@ The player API can register player models and update the player's appearance.
|
||||||
animation_speed = 30, -- Default animation speed, in FPS
|
animation_speed = 30, -- Default animation speed, in FPS
|
||||||
textures = {"character.png", }, -- Default array of textures
|
textures = {"character.png", }, -- Default array of textures
|
||||||
visual_size = {x = 1, y = 1}, -- Used to scale the model
|
visual_size = {x = 1, y = 1}, -- Used to scale the model
|
||||||
|
stepheight = 0.6, -- In nodes
|
||||||
animations = {
|
animations = {
|
||||||
-- <anim_name> = {x = <start_frame>, y = <end_frame>},
|
-- <anim_name> = {x = <start_frame>, y = <end_frame>},
|
||||||
foo = {x = 0, y = 19},
|
-- The first 5 animations are required by the API
|
||||||
bar = {x = 20, y = 39},
|
stand = {x = 0, y = 79},
|
||||||
-- ...
|
lay = {x = 162, y = 166},
|
||||||
|
walk = {x = 168, y = 187},
|
||||||
|
mine = {x = 189, y = 198},
|
||||||
|
walk_mine = {x = 200, y = 219},
|
||||||
|
-- The `sit` animation is only required by other Minetest Game mods
|
||||||
|
sit = {x = 81, y = 160},
|
||||||
|
-- More animations can be added
|
||||||
},
|
},
|
||||||
collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3}, -- In nodes from feet position
|
collisionbox = {
|
||||||
stepheight = 0.6, -- In nodes
|
-- Defined for each animation
|
||||||
eye_height = 1.47, -- In nodes above feet position
|
-- <anim_name> = {<xmin>, <ymin>, <zmin>, <xmax>, <ymax>, <zmax>},
|
||||||
|
-- Min/max positions are in nodes from feet position
|
||||||
|
stand = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
|
||||||
|
walk = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
|
||||||
|
mine = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
|
||||||
|
walk_mine = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
|
||||||
|
lay = {-0.6, 0.0, -0.6, 0.6, 0.3, 0.6},
|
||||||
|
sit = {-0.3, 0.0, -0.3, 0.3, 1.0, 0.3},
|
||||||
|
},
|
||||||
|
eye_height = {
|
||||||
|
-- Defined for each animation
|
||||||
|
-- In nodes above feet position
|
||||||
|
stand = 1.47,
|
||||||
|
walk = 1.47,
|
||||||
|
mine = 1.47,
|
||||||
|
walk_mine = 1.47,
|
||||||
|
lay = 0.3,
|
||||||
|
sit = 0.8,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
Alternatively, `collisionbox` and `eye_height` can be defined as single values applied
|
||||||
|
to all animations:
|
||||||
|
|
||||||
|
{
|
||||||
|
collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
|
||||||
|
eye_height = 1.47,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
-- Minetest 0.4 mod: player
|
|
||||||
-- See README.txt for licensing and other information.
|
|
||||||
|
|
||||||
player_api = {}
|
player_api = {}
|
||||||
|
|
||||||
-- Player animation blending
|
-- Player animation blending
|
||||||
|
@ -40,14 +37,13 @@ function player_api.set_model(player, model_name)
|
||||||
if player_model[name] == model_name then
|
if player_model[name] == model_name then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
-- collisionbox and eye_height are set in set_animation()
|
||||||
player:set_properties({
|
player:set_properties({
|
||||||
mesh = model_name,
|
mesh = model_name,
|
||||||
textures = player_textures[name] or model.textures,
|
textures = player_textures[name] or model.textures,
|
||||||
visual = "mesh",
|
visual = "mesh",
|
||||||
visual_size = model.visual_size or {x = 1, y = 1},
|
visual_size = model.visual_size or {x = 1, y = 1},
|
||||||
collisionbox = model.collisionbox or {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
|
|
||||||
stepheight = model.stepheight or 0.6,
|
stepheight = model.stepheight or 0.6,
|
||||||
eye_height = model.eye_height or 1.47,
|
|
||||||
})
|
})
|
||||||
player_api.set_animation(player, "stand")
|
player_api.set_animation(player, "stand")
|
||||||
else
|
else
|
||||||
|
@ -72,6 +68,7 @@ function player_api.set_textures(player, textures)
|
||||||
end
|
end
|
||||||
|
|
||||||
function player_api.set_animation(player, anim_name, speed)
|
function player_api.set_animation(player, anim_name, speed)
|
||||||
|
-- Return if animation already applied to player
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
if player_anim[name] == anim_name then
|
if player_anim[name] == anim_name then
|
||||||
return
|
return
|
||||||
|
@ -83,6 +80,17 @@ function player_api.set_animation(player, anim_name, speed)
|
||||||
local anim = model.animations[anim_name]
|
local anim = model.animations[anim_name]
|
||||||
player_anim[name] = anim_name
|
player_anim[name] = anim_name
|
||||||
player:set_animation(anim, speed or model.animation_speed, animation_blend)
|
player:set_animation(anim, speed or model.animation_speed, animation_blend)
|
||||||
|
-- Set animation-dependent properties
|
||||||
|
local eyeh
|
||||||
|
if type(model.eye_height) == "table" then
|
||||||
|
eyeh = model.eye_height[anim_name]
|
||||||
|
else -- number
|
||||||
|
eyeh = model.eye_height
|
||||||
|
end
|
||||||
|
player:set_properties({
|
||||||
|
collisionbox = model.collisionbox[anim_name] or model.collisionbox,
|
||||||
|
eye_height = eyeh,
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_leaveplayer(function(player)
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
-- player/init.lua
|
|
||||||
|
|
||||||
dofile(minetest.get_modpath("player_api") .. "/api.lua")
|
dofile(minetest.get_modpath("player_api") .. "/api.lua")
|
||||||
|
|
||||||
-- Default player appearance
|
-- Default player appearance
|
||||||
player_api.register_model("character.b3d", {
|
player_api.register_model("character.b3d", {
|
||||||
animation_speed = 30,
|
animation_speed = 30,
|
||||||
textures = {"character.png"},
|
textures = {"character.png"},
|
||||||
|
stepheight = 0.6,
|
||||||
animations = {
|
animations = {
|
||||||
-- Standard animations.
|
|
||||||
stand = {x = 0, y = 79},
|
stand = {x = 0, y = 79},
|
||||||
lay = {x = 162, y = 166},
|
lay = {x = 162, y = 166},
|
||||||
walk = {x = 168, y = 187},
|
walk = {x = 168, y = 187},
|
||||||
|
@ -15,9 +13,22 @@ player_api.register_model("character.b3d", {
|
||||||
walk_mine = {x = 200, y = 219},
|
walk_mine = {x = 200, y = 219},
|
||||||
sit = {x = 81, y = 160},
|
sit = {x = 81, y = 160},
|
||||||
},
|
},
|
||||||
collisionbox = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
|
collisionbox = {
|
||||||
stepheight = 0.6,
|
stand = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
|
||||||
eye_height = 1.47,
|
walk = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
|
||||||
|
mine = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
|
||||||
|
walk_mine = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
|
||||||
|
lay = {-0.6, 0.0, -0.6, 0.6, 0.3, 0.6},
|
||||||
|
sit = {-0.3, 0.0, -0.3, 0.3, 1.0, 0.3},
|
||||||
|
},
|
||||||
|
eye_height = {
|
||||||
|
stand = 1.47,
|
||||||
|
walk = 1.47,
|
||||||
|
mine = 1.47,
|
||||||
|
walk_mine = 1.47,
|
||||||
|
lay = 0.3,
|
||||||
|
sit = 0.8,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
-- Update appearance when the player joins
|
-- Update appearance when the player joins
|
||||||
|
|
Loading…
Add table
Reference in a new issue