Make automatic_rotate relative, allow setting rotation (#8468)
authorANAND <ClobberXD@gmail.com>
Sat, 16 May 2020 19:42:31 +0000 (01:12 +0530)
committerGitHub <noreply@github.com>
Sat, 16 May 2020 19:42:31 +0000 (21:42 +0200)
automatic_rotate does not make sense if it is absolute. Make it relative.

To avoid bouncing, set_rotation did not update the client when automatic_rotate was set. That's no longer necessary because the new spinning method applies the rotation on top of the current one, and the updates are necessary for set_rotation to actually transform the object.

Co-authored-by: ANAND <ClobberXD@gmail.com>
Co-authored-by: Pedro Gimeno <pgimeno@users.noreply.notabug.org>
doc/lua_api.txt
src/client/content_cao.cpp

index 9685e8307b65a4ec435eee2bc38d3b133e3530e7..07758c23747732506fd52595a99bed1b0c6702db 100644 (file)
@@ -6555,6 +6555,7 @@ Player properties need to be saved manually.
 
         automatic_rotate = 0,
         -- Set constant rotation in radians per second, positive or negative.
+        -- Object rotates along the local Y-axis, and works with set_rotation.
         -- Set to 0 to disable constant rotation.
 
         stepheight = 0,
index eb1dad22bb453db2f0858aef6ce34a9ec8e4cac6..867bbf2c8f1b6388ff148a21144d337ddf08cbb4 100644 (file)
@@ -1077,10 +1077,13 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
                        updateTextures(m_previous_texture_modifier);
                }
        }
+
        if (!getParent() && std::fabs(m_prop.automatic_rotate) > 0.001) {
-               m_rotation.Y += dtime * m_prop.automatic_rotate * 180 / M_PI;
-               rot_translator.val_current = m_rotation;
-               updateNodePos();
+               // This is the child node's rotation. It is only used for automatic_rotate.
+               v3f local_rot = node->getRotation();
+               local_rot.Y = modulo360f(local_rot.Y - dtime * core::RADTODEG *
+                               m_prop.automatic_rotate);
+               node->setRotation(local_rot);
        }
 
        if (!getParent() && m_prop.automatic_face_movement_dir &&
@@ -1501,11 +1504,7 @@ void GenericCAO::processMessage(const std::string &data)
                m_position = readV3F32(is);
                m_velocity = readV3F32(is);
                m_acceleration = readV3F32(is);
-
-               if (std::fabs(m_prop.automatic_rotate) < 0.001f)
-                       m_rotation = readV3F32(is);
-               else
-                       readV3F32(is);
+               m_rotation = readV3F32(is);
 
                m_rotation = wrapDegrees_0_360_v3f(m_rotation);
                bool do_interpolate = readU8(is);