summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPilzAdam <pilzadam@minetest.net>2013-08-18 15:49:09 +0200
committerPilzAdam <pilzadam@minetest.net>2013-09-10 23:31:44 +0200
commit4feea0ac6845ea025e8784f63f48e567d1d24c22 (patch)
tree2b435201e2198d87ed37210b6e332f2ae4cc597a
parent681e136d5f8a6847a356f2ef53c4c28123a4cbae (diff)
downloadminetest-4feea0ac6845ea025e8784f63f48e567d1d24c22.tar.gz
minetest-4feea0ac6845ea025e8784f63f48e567d1d24c22.tar.bz2
minetest-4feea0ac6845ea025e8784f63f48e567d1d24c22.zip
Add offset to automatic_face_movement_dir
-rw-r--r--doc/lua_api.txt3
-rw-r--r--src/clientserver.h3
-rw-r--r--src/content_cao.cpp5
-rw-r--r--src/content_sao.cpp5
-rw-r--r--src/object_properties.cpp5
-rw-r--r--src/object_properties.h1
-rw-r--r--src/script/common/c_content.cpp10
7 files changed, 24 insertions, 8 deletions
diff --git a/doc/lua_api.txt b/doc/lua_api.txt
index 028669c62..c63ea29e1 100644
--- a/doc/lua_api.txt
+++ b/doc/lua_api.txt
@@ -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)
diff --git a/src/clientserver.h b/src/clientserver.h
index fb442cfc0..67a4846a6 100644
--- a/src/clientserver.h
+++ b/src/clientserver.h
@@ -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
diff --git a/src/content_cao.cpp b/src/content_cao.cpp
index bb8dad032..e97e3a1be 100644
--- a/src/content_cao.cpp
+++ b/src/content_cao.cpp
@@ -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();
}
}
diff --git a/src/content_sao.cpp b/src/content_sao.cpp
index 9b4ae6100..85ab8d307 100644
--- a/src/content_sao.cpp
+++ b/src/content_sao.cpp
@@ -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;
}
}
diff --git a/src/object_properties.cpp b/src/object_properties.cpp
index b6ad9f6df..f560f5934 100644
--- a/src/object_properties.cpp
+++ b/src/object_properties.cpp
@@ -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
diff --git a/src/object_properties.h b/src/object_properties.h
index edc9c39d6..4b7f9a5eb 100644
--- a/src/object_properties.h
+++ b/src/object_properties.h
@@ -46,6 +46,7 @@ struct ObjectProperties
float automatic_rotate;
f32 stepheight;
bool automatic_face_movement_dir;
+ f32 automatic_face_movement_dir_offset;
ObjectProperties();
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 3a3a70860..a035b32a2 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -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);
}
/******************************************************************************/