fix transform:set_pos

This commit is contained in:
MihailRis 2024-07-11 01:10:23 +03:00
parent a105a4f2c7
commit ee768f878c
3 changed files with 13 additions and 5 deletions

View File

@ -2,10 +2,12 @@ history = session.get_entry("commands_history")
history_pointer = #history
function setup_variables()
local x,y,z = player.get_pos(hud.get_player())
local pid = hud.get_player()
local x,y,z = player.get_pos(pid)
console.set('pos.x', x)
console.set('pos.y', y)
console.set('pos.z', z)
console.set('entity.id', player.get_entity(pid):get_uid())
end
function on_history_up()

View File

@ -106,10 +106,14 @@ console.add_command(
)
console.add_command(
"tp obj:sel=$obj.id x:num~pos.x y:num~pos.y z:num~pos.z",
"Teleport object",
"tp entity:sel=$entity.id x:num~pos.x y:num~pos.y z:num~pos.z",
"Teleport entity",
function (args, kwargs)
player.set_pos(unpack(args))
local eid, x, y, z = unpack(args)
local entity = entities.get(eid)
if entity ~= nil then
entity.transform:set_pos({x, y, z})
end
end
)
console.add_command(

View File

@ -9,7 +9,9 @@ static int l_transform_get_pos(lua::State* L) {
static int l_transform_set_pos(lua::State* L) {
if (auto entity = get_entity(L, 1)) {
entity->getTransform().setPos(lua::tovec3(L, 2));
auto vec = lua::tovec3(L, 2);
entity->getTransform().setPos(vec);
entity->getRigidbody().hitbox.position = vec;
}
return 0;
}