Jump to content

[1.7.10] RotationYaw drives me nut


Frag

Recommended Posts

Hi guys,

 

I have a new water mob which is a fish. I have no issue moving it around in the water. BUT the rotation yaw gives me headaches.

 

It always seems that the mob moves sideways or backward before adjusting the yaw correctly.

 

It does work at some point, but the fish always travel some distance before having the correct yaw. I would like it to point in the correct direction BEFORE starting to move.

 

What am I doing wrong?

 

Is it because the client side get the yaw value too late, after the server start to send new positions?

 

This is how I calculate my yaw (look in bold) during the updateaitask while starting to move ... I took it from the ghast class in forge. I tested few methods, all with similar results.

 

 

 

public static void SwimTo(EntityFantasticFish aWaterMob, double xCoor, double yCoor, double zCoor, double speed)

{

 

if ((aWaterMob!=null) && (aWaterMob.isEntityAlive()))

{

if (!aWaterMob.worldObj.isRemote)

{

//Distance to target

double distX = Math.abs(xCoor - aWaterMob.posX);

double distY = Math.abs(yCoor - aWaterMob.posY);

double distZ = Math.abs(zCoor - aWaterMob.posZ);

double speedAdjustment;

 

 

if ((distX<=0.5) && (distY<=0.5) && (distZ<=0.5))

{

//Stay still

aWaterMob.setVelocity(0, 0, 0);

aWaterMob.SetCurrentSpeed(0F);

}

else

{

 

//Create vector

Vec3 vec3 = Vec3.createVectorHelper(xCoor - aWaterMob.posX, yCoor - aWaterMob.posY, zCoor - aWaterMob.posZ).normalize();

 

//Get approaching speed

speedAdjustment = ProvideApproachingSpeed(distX, distY, distZ);

 

//Set motion and angles

aWaterMob.motionX = (vec3.xCoord * speed)*speedAdjustment;

aWaterMob.motionY = (vec3.yCoord * speed)*speedAdjustment;

aWaterMob.motionZ = (vec3.zCoord * speed)*speedAdjustment;

 

//Yaw from the ghast code

aWaterMob.renderYawOffset = aWaterMob.rotationYaw = -((float)Math.atan2(aWaterMob.motionX, aWaterMob.motionZ)) * 180.0F / (float)Math.PI;

 

}

}

}

}

 

 

 

And this is what I have in the model class:

 

 

 

  public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity)

  {

    super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);

    EntityFantasticFish _fish = (EntityFantasticFish)entity;

   

    this.mouth.rotateAngleX = 0.17F*(MathHelper.cos(f2 * 0.06662F) ) + 0.8726646F;

    this.bodysection1.rotateAngleY = 0.2F *(MathHelper.cos(f2 * _fish.GetTailFlapSpeed() * 0.527F) );

    this.bodysection2.rotateAngleY = 0.2F *(MathHelper.cos(f2 *_fish.GetTailFlapSpeed() * 0.527F - (float)(Math.PI/6)) );

    this.bodysection3.rotateAngleY = 0.2F *(MathHelper.cos(f2 *  _fish.GetTailFlapSpeed() * 0.527F - (float)(Math.PI/3)) );

    this.bodysection4.rotateAngleY = 0.2F *(MathHelper.cos(f2 * _fish.GetTailFlapSpeed() * 0.527F - (float)(Math.PI/2)) );

    this.bodysection5.rotateAngleY = 0.2F *(MathHelper.cos(f2 *  _fish.GetTailFlapSpeed() * 0.527F - (float)(2*Math.PI/3)) );

    this.bodysection6.rotateAngleY = 0.2F *(MathHelper.cos(f2 * _fish.GetTailFlapSpeed() * 0.527F - (float)(5*Math.PI/6)) );

  }

 

 

 

 

Link to comment
Share on other sites

Try adjusting rotationYaw on both side, not only Server side.

 

I was under the impression that the server and client where always in synch as far as the basic rendering parameters (pitch, yaw, position). Am I wrong?

 

Any of you guys are doing manual synching for those rendering parameters?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.