mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 19: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
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue