Add offset to automatic_face_movement_dir
authorPilzAdam <pilzadam@minetest.net>
Sun, 18 Aug 2013 13:49:09 +0000 (15:49 +0200)
committerPilzAdam <pilzadam@minetest.net>
Tue, 10 Sep 2013 21:31:44 +0000 (23:31 +0200)
doc/lua_api.txt
src/clientserver.h
src/content_cao.cpp
src/content_sao.cpp
src/object_properties.cpp
src/object_properties.h
src/script/common/c_content.cpp

index 028669c62c5cc998fcbc31805ca9226b8a603d5b..c63ea29e120391b9beb973e83094cd96bdf20f9f 100644 (file)
@@ -1888,7 +1888,8 @@ Object Properties
     makes_footstep_sound = false,
     automatic_rotate = false,
     stepheight = 0,
-    automatic_face_movement_dir = false,
+    automatic_face_movement_dir = 0.0,
+    ^ automatically set yaw to movement direction; offset in degrees; false to disable
 }
 
 Entity definition (register_entity)
index fb442cfc0fdf2ee80708aa0f01788b545d60d4fd..67a4846a668797648c656c4cb7dcd034eaa9f5dd 100644 (file)
@@ -98,7 +98,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
                drowning, leveled and liquid_range added to ContentFeatures
                stepheight and collideWithObjects added to object properties
                version, heat and humidity transfer in MapBock
-               added new property to entities automatic_face_movement_dir
+               automatic_face_movement_dir and automatic_face_movement_dir_offset
+                       added to object properties
 */
 
 #define LATEST_PROTOCOL_VERSION 21
index bb8dad032eb7777e61305b8c00c56cd9e82133f2..e97e3a1beae912712c507fde32cda4bc38089fb9 100644 (file)
@@ -1211,8 +1211,9 @@ public:
                        updateNodePos();
                }
 
-               if (getParent() == NULL && m_prop.automatic_face_movement_dir){
-                       m_yaw = atan2(m_velocity.Z,m_velocity.X) * 180 / M_PI;
+               if (getParent() == NULL && m_prop.automatic_face_movement_dir &&
+                               (fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001)){
+                       m_yaw = atan2(m_velocity.Z,m_velocity.X) * 180 / M_PI + m_prop.automatic_face_movement_dir_offset;
                        updateNodePos();
                }
        }
index 9b4ae6100e0eec7d422de0f94f4e4558b7576468..85ab8d307abe4bb4e36682eea48f92ffe6a6c8bc 100644 (file)
@@ -527,8 +527,9 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
                        m_velocity += dtime * m_acceleration;
                }
 
-               if(m_prop.automatic_face_movement_dir){
-                       m_yaw = atan2(m_velocity.Z,m_velocity.X) * 180 / M_PI;
+               if((m_prop.automatic_face_movement_dir) &&
+                               (fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001)){
+                       m_yaw = atan2(m_velocity.Z,m_velocity.X) * 180 / M_PI + m_prop.automatic_face_movement_dir_offset;
                }
        }
 
index b6ad9f6dfa85057b3371232b56b6235e008eab37..f560f59343a6d6507e6993d8b2aaacb43c84b2af 100644 (file)
@@ -41,7 +41,8 @@ ObjectProperties::ObjectProperties():
        makes_footstep_sound(false),
        automatic_rotate(0),
        stepheight(0),
-       automatic_face_movement_dir(false)
+       automatic_face_movement_dir(false),
+       automatic_face_movement_dir_offset(0.0)
 {
        textures.push_back("unknown_object.png");
        colors.push_back(video::SColor(255,255,255,255));
@@ -104,6 +105,7 @@ void ObjectProperties::serialize(std::ostream &os) const
        writeU8(os, collideWithObjects);
        writeF1000(os,stepheight);
        writeU8(os, automatic_face_movement_dir);
+       writeF1000(os, automatic_face_movement_dir_offset);
        // Add stuff only at the bottom.
        // Never remove anything, because we don't want new versions of this
 }
@@ -139,6 +141,7 @@ void ObjectProperties::deSerialize(std::istream &is)
                        collideWithObjects = readU8(is);
                        stepheight = readF1000(is);
                        automatic_face_movement_dir = readU8(is);
+                       automatic_face_movement_dir_offset = readF1000(is);
                }catch(SerializationError &e){}
        }
        else
index edc9c39d670dbd0f8bf715408f9d59123eddc06c..4b7f9a5eb4f5c8501bf1d31f497dd73d08e8b24e 100644 (file)
@@ -46,6 +46,7 @@ struct ObjectProperties
        float automatic_rotate;
        f32 stepheight;
        bool automatic_face_movement_dir;
+       f32 automatic_face_movement_dir_offset;
 
 
        ObjectProperties();
index 3a3a7086052cf214864bb218794997a7791045f7..a035b32a2d644820bdea4ef202ced1d1246d6afb 100644 (file)
@@ -191,7 +191,15 @@ void read_object_properties(lua_State *L, int index,
        getfloatfield(L, -1, "automatic_rotate", prop->automatic_rotate);
        getfloatfield(L, -1, "stepheight", prop->stepheight);
        prop->stepheight*=BS;
-       getboolfield(L, -1, "automatic_face_movement_dir", prop->automatic_face_movement_dir);
+       lua_getfield(L, -1, "automatic_face_movement_dir");
+       if (lua_isnumber(L, -1)) {
+               prop->automatic_face_movement_dir = true;
+               prop->automatic_face_movement_dir_offset = luaL_checknumber(L, -1);
+       } else if (lua_isboolean(L, -1)) {
+               prop->automatic_face_movement_dir = lua_toboolean(L, -1);
+               prop->automatic_face_movement_dir_offset = 0.0;
+       }
+       lua_pop(L, 1);
 }
 
 /******************************************************************************/