I am trying to create a worm like entity in Minecraft. it is extremely long so it needed to be broken up into multiple parts

Each part follows the previous so 9>8>7>6>5>4>3>2>1>0

0 being the head of the worm

Each part uses trig in order to find where to place / rotate itself based on the position and rotation of the part it is following

`` public void pseudoChild(Entity parent, float length, Entity child) {float parentYaw = (parent.rotationYaw + 90) * 0.0174533F;float parentPitch = (parent.rotationPitch) * 0.0174533F;double x = ((length * MathHelper.cos(parentPitch) * MathHelper.cos(parentYaw)) + parent.posX);double y = ((length * MathHelper.sin(parentPitch)) + parent.posY);double z = (length * MathHelper.cos(parentPitch) * MathHelper.sin(parentYaw)) + parent.posZ;float yaw = child.rotationYaw + ((parent.rotationYaw - child.rotationYaw) * 0.1F);float pitch = child.rotationPitch + ((parent.rotationPitch - child.rotationPitch) * 0.1F);child.setLocationAndAngles(x, y, z, yaw, pitch);}``

the problem that I am having is when the head rotates to or from 180/-180 it flips to one or the other. I printed out the yaw in the log to show what happens

``181.59375182.59375183.59375184.59375-174.78125-173.78125-172.78125-171.78125``

This causes the body segments to briefly rotate 360 degrees from positive to negative or vise versa depending on the rotation direction.

A vid of the phenomenon

https://youtu.be/8PYXfl3101k

I am not sure how to solve this issue without using my own custom floats for pitch and yaw and forgo using the minecraft variables as they flip suddenly at 180/-180

Any help is appreciated.

Thank you

Top