diff options
author | you <ovvv@web.de> | 2018-03-31 14:48:38 +0200 |
---|---|---|
committer | SmallJoker <mk939@ymail.com> | 2018-03-31 14:50:17 +0200 |
commit | 93eb0794d6f7366df5fb375855b2e5e5888304c6 (patch) | |
tree | f07bbb4af6148aecb28c3441232601c28f33500b /src | |
parent | 0a8ca598915a906e665141dc79fc0c1bbab8cc91 (diff) | |
download | minetest-93eb0794d6f7366df5fb375855b2e5e5888304c6.tar.gz minetest-93eb0794d6f7366df5fb375855b2e5e5888304c6.tar.bz2 minetest-93eb0794d6f7366df5fb375855b2e5e5888304c6.zip |
ObjectRef: Add add_velocity() (#3208)
Allow changing the velocity of objects relatively to their current velocity
Diffstat (limited to 'src')
-rw-r--r-- | src/content_sao.h | 4 | ||||
-rw-r--r-- | src/script/lua_api/l_object.cpp | 15 | ||||
-rw-r--r-- | src/script/lua_api/l_object.h | 3 |
3 files changed, 22 insertions, 0 deletions
diff --git a/src/content_sao.h b/src/content_sao.h index 509f477dd..3f75a7890 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -121,6 +121,10 @@ public: s16 getHP() const; /* LuaEntitySAO-specific */ void setVelocity(v3f velocity); + void addVelocity(v3f velocity) + { + m_velocity += velocity; + } v3f getVelocity(); void setAcceleration(v3f acceleration); v3f getAcceleration(); diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index e4c478df7..b3c3bdf66 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -850,6 +850,20 @@ int ObjectRef::l_set_velocity(lua_State *L) return 0; } +// add_velocity(self, {x=num, y=num, z=num}) +int ObjectRef::l_add_velocity(lua_State *L) +{ + NO_MAP_LOCK_REQUIRED; + ObjectRef *ref = checkobject(L, 1); + LuaEntitySAO *co = getluaobject(ref); + if (!co) + return 0; + v3f pos = checkFloatPos(L, 2); + // Do it + co->addVelocity(pos); + return 0; +} + // get_velocity(self) int ObjectRef::l_get_velocity(lua_State *L) { @@ -1840,6 +1854,7 @@ const luaL_Reg ObjectRef::methods[] = { luamethod(ObjectRef, get_nametag_attributes), // LuaEntitySAO-only luamethod_aliased(ObjectRef, set_velocity, setvelocity), + luamethod(ObjectRef, add_velocity), luamethod_aliased(ObjectRef, get_velocity, getvelocity), luamethod_aliased(ObjectRef, set_acceleration, setacceleration), luamethod_aliased(ObjectRef, get_acceleration, getacceleration), diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h index 58cfe7146..21c215c3f 100644 --- a/src/script/lua_api/l_object.h +++ b/src/script/lua_api/l_object.h @@ -161,6 +161,9 @@ private: // set_velocity(self, {x=num, y=num, z=num}) static int l_set_velocity(lua_State *L); + // add_velocity(self, {x=num, y=num, z=num}) + static int l_add_velocity(lua_State *L); + // get_velocity(self) static int l_get_velocity(lua_State *L); |