Jump to content

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


Frag

Recommended Posts

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

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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 ...

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

 

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They are heartless scammers, they ruined my life, by making me develop an interest in investing my hard-earned money. I deposited 67,000 USD which was later turned into 110,450 USD including my payout bonus, there was an impressive improvement in a few weeks, later I had an emergency and needed money to pay my insurance fee, I tried reaching out to them to collect the money I invested, they cut the live chats and got me harassed then I realized that I was being scammed. I just wanted my money back! I was advised by a friend to seek help from a recovery firm to assist me in recovering my invested funds, God was so kind I came across some great positive reviews about BETAFORT ONLINE on how they helped scammed victims like me to recover their lost cryptocurrency assets, I took no delay and got in touch with BETAFORT ONLINE, the Expert immediately looked into my case and after providing all the required information they need, and it took them less then a day to recover all my funds. And now I really feel obligated to recommend BETAFORT ONLINE and their team, their recovery strategies, and for working relentlessly to help me recover my funds. Feel free to reach out to BETAFORT ONLINE via google search and they will guide you on how to recover your invested funds, I advise everyone to be careful with these heartless cryptocurrency scammers.  
    • yeah I believe so, its been something deep with the modpack I'm guessing. ill fix each error it states if its saying to replace or download a mod but I'm not sure where to go from here. I have been spending days and have yet to find the issue    
    • It worked, thank you very much 😭
    • https://spark.lucko.me/0ZaR1OAi2F I use spark mod to do a scan and send it here to search for help and if someone know about this issue I dont know to much about, but one thing i see in the record of the minecraft launcher when i play says: can't keep up server overloaded and etc, etc.  I assign 6GB ram to minecraft from the 16 GB of my pc, and fps is not a problem...(no to much) its something about tic rate/second and i am in SINGLE PLAYER. The funny thing is, minecraft vanilla (No mods) works normaly. My mods list (130): https://imgur.com/a/kY3yQr1  Datapacks: https://imgur.com/CTDBe7D ResourcePacks: https://imgur.com/AztTOOw so plis, is someone help me T_T a work  a loot of time in downloading and trying to all mods work but i dont know what to do anymore. Last thing  I SPEAK SPANISH so... sorry if my english is a little scuff or ... werever... bad. Thanks :3
    • Whenever I try to create an world my game crashes. I´ve tried to figure it out myself but wasnt able to do it.   Here are the logs
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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