Jump to content

[1.7.10] Rendering many mobs ... they are all rendered synched?


Recommended Posts

Posted

Hi guys,

 

two short rendering questions for you. I wrote a fish mob that animate correctly, but I have two issues, which I am pretty sure one of you guys can help me out with.

 

1. I noticed that, when many mobs are together, they are all animated at the same sequence. I remember reading somewhere that you can insert some kind of random value to let them start at a different stage of the animation. But I can't find this article anymore ... someone could hint me out?

 

2. The following code section is my animation loop. The float value returned by _fish.GetTailFlapSpeed can be from 0 to 4. I noticed that when the value returned by this method is changed, than the animation jerk (look like it reset). I understand for sure that changing that value during the animation will change the result of the calculated angles, switching the rendered object angle on the spot ...which cause the jerking animation. But anyone of you could look at this simple code snipet and tell how I could avoid this? I am a bit new to rendering ... its getting in slowly but surely.

 

  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)) );
   }

Posted

1. Are you using Entity#ticksExisted anywhere to control your animation? If so, that value starts at 0 for all entities every time the world loads, so if you spawn a bunch, quit, then start again, they will all be synchronized. If that is the case, you can either do a hack such as adding a (small) random amount to their ticksExisted each time they are constructed on the client, or use some other field for your animation timer.

 

2. If you want smooth animations, you need to use partial ticks (the last float parameter of the method, I believe) and interpolate the rotation values between what it started at and what it should end at * partialTicks (a value that increases from 0 to 1 each tick; render ticks may be happen multiple times per regular tick depending on how fast the client side processes rendering).

Posted

1. Are you using Entity#ticksExisted anywhere to control your animation? If so, that value starts at 0 for all entities every time the world loads, so if you spawn a bunch, quit, then start again, they will all be synchronized. If that is the case, you can either do a hack such as adding a (small) random amount to their ticksExisted each time they are constructed on the client, or use some other field for your animation timer.

 

2. If you want smooth animations, you need to use partial ticks (the last float parameter of the method, I believe) and interpolate the rotation values between what it started at and what it should end at * partialTicks (a value that increases from 0 to 1 each tick; render ticks may be happen multiple times per regular tick depending on how fast the client side processes rendering).

 

1. Thanks CoolAlias ... THAT did the trick. Worked on the first try!

 

2. YEs the partial tick is the third parameters (which is the parameter named f2 in my case). My issue is that my _fish.gettailflapspeed can change abruptly between two ticks ...which will make a huge jump of angles ... causing a jerky motion. Was just wondering is someone could suggest something by looking at my line.

 

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

 

In this line, the value of _fish.GetTailFlapSpeed can change abruptly. Maybe there is a trick around from you rendering gurus ...

 

Posted

Unfortunately, my geometry / math skills are quite rusty, but I can usually make do by finding something in vanilla that is similar and then tweaking the values.

 

In this case, I'd recommend taking a look at the Iron Golem model, specifically the arm swinging animation when it attacks - that gives a fairly smooth up/down rotation that you could adapt to a horizontal one for your fish tail. The golem attack timer starts at 10 and decrements to 0, so the formula is multiplied in a way that 10-6 (or so) is moving up, and the rest is moving back down.

 

If you're not familiar with the unit circle, especially the sine and cosine oscillations between -1 and 1 as you travel around it, I recommend some Googling of that as it is the basis of probably all swinging animations.

Posted

With animation you really don't need to do math. You can just make an array containing all the angles in the cycle then step through them. I find that is a lot easier to "visualize" and also works for irregular movements whereas math mostly works for very regular movement.

 

This is also the way that real animators work -- they create a series of poses they like and cycle through them (like one of those books that you flip to animate a cartoon).

 

A fish is fairly regular in its motion so math works. But I bet it will take you more time to figure out the sine and cosine stuff than just having a cycle hard-coded.

 

I have a tutorial using the array-based pose method: http://jabelarminecraft.blogspot.com/p/introduction-first-of-all-to-understand.html

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

Yes I read your tutorial on the subject. This is gold.

 

Only thing is in my case, the table of values would need to be huge ... and with different speed, I would need many tables as well.

 

The only issue I am having now is that when the speed of the tail change(variable _tailspeed), there is a abrupt change in the result value attributed to this.bodysection4.rotateAngleY  ...

 

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

 

So let's say the _tailspeed in 0.2 ... here is the debug output. You will notice that when the _tailSpeed change from 0.2 to 0.7, the angle value jump too fast from -0.18 to -0.11 ...which cause the jerky motion. In the following trace, f2 is the tick.

 

f2: 1530.5969 Tail Speed: 0.2 Angle: -0.17856722

f2: 1530.917 Tail Speed: 0.2 Angle: -0.18150482

NEW TAIL FLAP SPEED IS SENT FROM SetCurrentTailFlapSpeed SPEED: 0.7

f2: 1531.2571 Tail Speed: 0.7 Angle: -0.11391987

f2: 1531.597 Tail Speed: 0.7 Angle: -0.09244798

f2: 1531.9171Tail Speed: 0.7 Angle: -0.07092236

 

I just need to find a way to smooth down those jumps ... If I cant find a way, I will go with large tables. But I would like to avoid this.

Posted

Sorry for the obvious question: why don't you just reduce the rate at which the tail speed value changes? I mean, you're in control of it... right?

 

Show the code that determines the tail speed if you need help on that.

 

This is actually not a bad idea at all! I could reduce it slightly at every tick to avoid major value changes. This is the reason why I posted here, sometimes getting ideas from people outside the project make you think outside the box. This is a VERY good hint. I will look it up and let you guys know!

 

 

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.