mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add base:player_animator component
This commit is contained in:
parent
b23f7e996f
commit
e8a8fb3d60
5 changed files with 39 additions and 4 deletions
|
|
@ -1,3 +1,6 @@
|
|||
{
|
||||
"components": [
|
||||
"base:player_animator"
|
||||
],
|
||||
"hitbox": [0.6, 1.8, 0.6]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ end
|
|||
|
||||
do -- setup visuals
|
||||
local matrix = mat4.idt()
|
||||
scale = item_models.setup(dropitem.id, rig)
|
||||
scale = item_models.setup(dropitem.id, rig, 0)
|
||||
local bodysize = math.min(scale[1], scale[2], scale[3]) * DROP_SCALE
|
||||
body:set_size({scale[1] * DROP_SCALE, bodysize, scale[3] * DROP_SCALE})
|
||||
mat4.mul(matrix, rotation, matrix)
|
||||
|
|
|
|||
27
res/content/base/scripts/components/player_animator.lua
Normal file
27
res/content/base/scripts/components/player_animator.lua
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
local item_models = require "core:item_models"
|
||||
|
||||
local tsf = entity.transform
|
||||
local body = entity.rigidbody
|
||||
local rig = entity.skeleton
|
||||
|
||||
local itemid = 0
|
||||
local itemIndex = rig:index("item")
|
||||
|
||||
local function refresh_model(id)
|
||||
if id == 0 then
|
||||
rig:set_model(itemIndex, "")
|
||||
else
|
||||
itemid = id
|
||||
local scale = item_models.setup(itemid, rig, itemIndex)
|
||||
rig:set_matrix(itemIndex, mat4.scale(scale))
|
||||
end
|
||||
end
|
||||
|
||||
function on_render()
|
||||
local invid, slotid = player.get_inventory()
|
||||
local id, _ = inventory.get(invid, slotid)
|
||||
if id ~= itemid then
|
||||
refresh_model(id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -9,6 +9,10 @@
|
|||
"name": "head",
|
||||
"model": "player-head",
|
||||
"offset": [0, 0.4, 0]
|
||||
},
|
||||
{
|
||||
"name": "item",
|
||||
"offset": [0.26, 0, -0.23]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
local function setup(id, rig)
|
||||
local function setup(id, rig, index)
|
||||
rig:set_model(index, "drop-block")
|
||||
local icon = item.icon(id)
|
||||
local size = {1.0, 1.0, 1.0}
|
||||
if icon:find("^block%-previews%:") then
|
||||
|
|
@ -6,7 +7,7 @@ local function setup(id, rig)
|
|||
model = block.get_model(bid)
|
||||
if model == "X" then
|
||||
size = {1.0, 0.3, 1.0}
|
||||
rig:set_model(0, "drop-item")
|
||||
rig:set_model(index, "drop-item")
|
||||
rig:set_texture("$0", icon)
|
||||
else
|
||||
if model == "aabb" then
|
||||
|
|
@ -21,7 +22,7 @@ local function setup(id, rig)
|
|||
end
|
||||
else
|
||||
size = {1.0, 0.3, 1.0}
|
||||
rig:set_model(0, "drop-item")
|
||||
rig:set_model(index, "drop-item")
|
||||
rig:set_texture("$0", icon)
|
||||
end
|
||||
return size
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue