1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-12 16:58:39 +00:00

Add support for limiting rotation of automatic face movement dir entitys

This commit is contained in:
Sapier 2015-12-15 00:03:18 +01:00 committed by Sapier
parent 06632205d8
commit 70ea5d552e
5 changed files with 37 additions and 5 deletions

View file

@ -283,8 +283,20 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
}
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;
(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;
float max_rotation_delta =
dtime * m_prop.automatic_face_movement_max_rotation_per_sec;
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;
} else {
m_yaw = optimal_yaw;
}
}
}