update entity.spawn(...)

This commit is contained in:
MihailRis 2024-06-27 07:50:26 +03:00
parent 94dd69350d
commit 1ca0761f49
2 changed files with 4 additions and 3 deletions

View File

@ -5,7 +5,8 @@ function on_hud_open()
input.add_callback("player.drop", function ()
local pid = hud.get_player()
local pvel = {player.get_vel(pid)}
local eid = entity.spawn("base:drop")
local ppos = vec3.add({player.get_pos(pid)}, {0, 0.7, 0})
local eid = entity.spawn("base:drop", ppos)
local throw_force = vec3.mul(player.get_dir(pid), DROP_FORCE)
Rigidbody.set_vel(eid, vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL)))
Transform.set_rot(eid, mat4.rotate({0, 1, 0}, math.random() * 360))

View File

@ -24,10 +24,10 @@ static std::optional<Entity> get_entity(lua::State* L, int idx) {
static int l_spawn(lua::State* L) {
auto level = controller->getLevel();
auto player = hud->getPlayer();
auto defname = lua::tostring(L, 1);
auto& def = content->entities.require(defname);
auto id = level->entities->spawn(def, player->camera->position);
auto pos = lua::tovec3(L, 2);
auto id = level->entities->spawn(def, pos);
return lua::pushinteger(L, id);
}