Posted February 26, 201411 yr Whenever you make a mob, in your render file (I think) there is a setRotationAngles() method right? In that you do all sorts of weird math. Now I never understood how that worked. Can someone tell me how you choose the correct rotation angles for the mob? Or someone explain the math? Or do you guys use a different method I don't know of? Add me on Skype: AblazeTheBest. Send a message saying "#HeyAblaze" Currently: Making a mod!
February 26, 201411 yr Author Sorry, but bump. Add me on Skype: AblazeTheBest. Send a message saying "#HeyAblaze" Currently: Making a mod!
February 26, 201411 yr Hi The math usually uses sin and cos because this gives nice "smooth" animations instead of jerky changes in direction, a bit like a swinging pendulum. It's hard to explain this in a few lines, this link might give you a bit of an idea about how sine and cosine make the motions "smooth", but to really properly understand it you probably need to study up a bit on trigonometry. http://www2.seminolestate.edu/lvosbury/SineCosine.htm An example from the ocelot code: this.ocelotBackLeftLeg.rotateAngleX = MathHelper.cos(animationTime * 0.6662F) * 1.0F * maximumSwingAngle; this.ocelotBackRightLeg.rotateAngleX = MathHelper.cos(animationTime * 0.6662F + 0.3F) * 1.0F * maximumSwingAngle; this.ocelotFrontLeftLeg.rotateAngleX = MathHelper.cos(animationTime * 0.6662F + (float)Math.PI + 0.3F) * 1.0F * maximumSwingAngle; this.ocelotFrontRightLeg.rotateAngleX = MathHelper.cos(animationTime * 0.6662F + (float)Math.PI) * 1.0F * maximumSwingAngle; this.ocelotTail2.rotateAngleX = 1.7278761F + ((float)Math.PI / 10F) * MathHelper.cos(animationTime) * maximumSwingAngle; this.ocelotTail2.rotateAngleX = 1.7278761F + ((float)Math.PI / 10F) * MathHelper.cos(par1) * par2; If we just look at the backleftleg - we are changing the rotation angle around the x axis, which is the side of the ocelot, so the leg is swinging forwards and backwards. If you have the function angle = cos(animationTime) it converts the animationTime into an angle For example if animationTime is in seconds: when animationTime is 0, cos(0) = 1 so the angle is set to 1. animationTime increases a bit, say to about 0.5. cos(0.5) is about 0.87, so the angle is set to 0.87 at 1 second, cos(1) = 0.54 at 1.5 seconds, cos(1.5) is approximately 0 at 2 seconds, cos (2) is approximately -0.4 And if you keep increasing the time, you'll find that the cos() oscillates smoothly between +1 and -1 in a repeating cycle. So you've converted your animationTime in seconds into a smoothly swinging angle back and forth. Every 6.3 seconds or so, the animation repeats (the exact number is 2 * Math.PI). There are a couple of extra tricks - if you want the animation to move faster or slower, you multiply the animationTime by a larger or smaller number. If you want the angle to swing by larger amounts, you multiply the cos by a larger number. If you've got two animations and you want to delay one of them a bit (i.e. one of the legs swings ahead of the other one) you add a delay time to your animation time So in the ocelot example, this.ocelotFrontLeftLeg.rotateAngleX = MathHelper.cos(animationTime * 0.6662F + (float)Math.PI + 0.3F) * 1.0F * maximumSwingAngle; we are slowing down the animation a bit (* 0.6662F) and we are delaying it a bit Math.PI + 0.3F and we are making the leg swing more (* maximumSwingAngle). Choosing the correct values is pretty much a matter of trial and error, with some hints based on vanilla code. If you're animating something similar to a vanilla creature, I'd suggest you look at the values it uses to get a good starting point. -TGG
February 26, 201411 yr Author Hi The math usually uses sin and cos because this gives nice "smooth" animations instead of jerky changes in direction, a bit like a swinging pendulum. It's hard to explain this in a few lines, this link might give you a bit of an idea about how sine and cosine make the motions "smooth", but to really properly understand it you probably need to study up a bit on trigonometry. http://www2.seminolestate.edu/lvosbury/SineCosine.htm An example from the ocelot code: this.ocelotBackLeftLeg.rotateAngleX = MathHelper.cos(animationTime * 0.6662F) * 1.0F * maximumSwingAngle; this.ocelotBackRightLeg.rotateAngleX = MathHelper.cos(animationTime * 0.6662F + 0.3F) * 1.0F * maximumSwingAngle; this.ocelotFrontLeftLeg.rotateAngleX = MathHelper.cos(animationTime * 0.6662F + (float)Math.PI + 0.3F) * 1.0F * maximumSwingAngle; this.ocelotFrontRightLeg.rotateAngleX = MathHelper.cos(animationTime * 0.6662F + (float)Math.PI) * 1.0F * maximumSwingAngle; this.ocelotTail2.rotateAngleX = 1.7278761F + ((float)Math.PI / 10F) * MathHelper.cos(animationTime) * maximumSwingAngle; this.ocelotTail2.rotateAngleX = 1.7278761F + ((float)Math.PI / 10F) * MathHelper.cos(par1) * par2; If we just look at the backleftleg - we are changing the rotation angle around the x axis, which is the side of the ocelot, so the leg is swinging forwards and backwards. If you have the function angle = cos(animationTime) it converts the animationTime into an angle For example if animationTime is in seconds: when animationTime is 0, cos(0) = 1 so the angle is set to 1. animationTime increases a bit, say to about 0.5. cos(0.5) is about 0.87, so the angle is set to 0.87 at 1 second, cos(1) = 0.54 at 1.5 seconds, cos(1.5) is approximately 0 at 2 seconds, cos (2) is approximately -0.4 And if you keep increasing the time, you'll find that the cos() oscillates smoothly between +1 and -1 in a repeating cycle. So you've converted your animationTime in seconds into a smoothly swinging angle back and forth. Every 6.3 seconds or so, the animation repeats (the exact number is 2 * Math.PI). There are a couple of extra tricks - if you want the animation to move faster or slower, you multiply the animationTime by a larger or smaller number. If you want the angle to swing by larger amounts, you multiply the cos by a larger number. If you've got two animations and you want to delay one of them a bit (i.e. one of the legs swings ahead of the other one) you add a delay time to your animation time So in the ocelot example, this.ocelotFrontLeftLeg.rotateAngleX = MathHelper.cos(animationTime * 0.6662F + (float)Math.PI + 0.3F) * 1.0F * maximumSwingAngle; we are slowing down the animation a bit (* 0.6662F) and we are delaying it a bit Math.PI + 0.3F and we are making the leg swing more (* maximumSwingAngle). Choosing the correct values is pretty much a matter of trial and error, with some hints based on vanilla code. If you're animating something similar to a vanilla creature, I'd suggest you look at the values it uses to get a good starting point. -TGG Alright, I'll keep this in mind while making a mob. I wanted to make a "Bookworm" boss mob, which spawns in my "Book" dimension. So I wanted those sway kind of motions, similar to a snake or a worm. Add me on Skype: AblazeTheBest. Send a message saying "#HeyAblaze" Currently: Making a mod!
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.