aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/content_cao.cpp16
-rw-r--r--src/content_sao.cpp20
2 files changed, 18 insertions, 18 deletions
diff --git a/src/content_cao.cpp b/src/content_cao.cpp
index 861dc83e7..7b6570653 100644
--- a/src/content_cao.cpp
+++ b/src/content_cao.cpp
@@ -904,19 +904,19 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
}
if (!getParent() && m_prop.automatic_face_movement_dir &&
- (fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001))
- {
- float optimal_yaw = atan2(m_velocity.Z,m_velocity.X) * 180 / M_PI
+ (fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001)) {
+
+ float target_yaw = atan2(m_velocity.Z, m_velocity.X) * 180 / M_PI
+ m_prop.automatic_face_movement_dir_offset;
float max_rotation_delta =
dtime * m_prop.automatic_face_movement_max_rotation_per_sec;
+ float delta = wrapDegrees_0_360(target_yaw - m_yaw);
- if ((m_prop.automatic_face_movement_max_rotation_per_sec > 0) &&
- (fabs(m_yaw - optimal_yaw) > max_rotation_delta)) {
-
- m_yaw = optimal_yaw < m_yaw ? m_yaw - max_rotation_delta : m_yaw + max_rotation_delta;
+ if (delta > max_rotation_delta && 360 - delta > max_rotation_delta) {
+ m_yaw += (delta < 180) ? max_rotation_delta : -max_rotation_delta;
+ m_yaw = wrapDegrees_0_360(m_yaw);
} else {
- m_yaw = optimal_yaw;
+ m_yaw = target_yaw;
}
updateNodePos();
}
diff --git a/src/content_sao.cpp b/src/content_sao.cpp
index e2bfdbef2..61384493a 100644
--- a/src/content_sao.cpp
+++ b/src/content_sao.cpp
@@ -372,20 +372,20 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
m_velocity += dtime * m_acceleration;
}
- if((m_prop.automatic_face_movement_dir) &&
- (fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001))
- {
- float optimal_yaw = atan2(m_velocity.Z,m_velocity.X) * 180 / M_PI
- + m_prop.automatic_face_movement_dir_offset;
+ if (m_prop.automatic_face_movement_dir &&
+ (fabs(m_velocity.Z) > 0.001 || fabs(m_velocity.X) > 0.001)) {
+
+ float target_yaw = atan2(m_velocity.Z, m_velocity.X) * 180 / M_PI
+ + m_prop.automatic_face_movement_dir_offset;
float max_rotation_delta =
dtime * m_prop.automatic_face_movement_max_rotation_per_sec;
+ float delta = wrapDegrees_0_360(target_yaw - m_yaw);
- if ((m_prop.automatic_face_movement_max_rotation_per_sec > 0) &&
- (fabs(m_yaw - optimal_yaw) > max_rotation_delta)) {
-
- m_yaw = optimal_yaw < m_yaw ? m_yaw - max_rotation_delta : m_yaw + max_rotation_delta;
+ if (delta > max_rotation_delta && 360 - delta > max_rotation_delta) {
+ m_yaw += (delta < 180) ? max_rotation_delta : -max_rotation_delta;
+ m_yaw = wrapDegrees_0_360(m_yaw);
} else {
- m_yaw = optimal_yaw;
+ m_yaw = target_yaw;
}
}
}