Jump to content

[1.7.2] [animation] how to make blades rotate ??


3izzo

Recommended Posts

adding a mini helicopter want the blades (Shape 19 ,20 ) to rotate



package thrizzo.minibots.model;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.util.MathHelper;

public class ModelHelicopter extends ModelBase
{
  //fields
    ModelRenderer Shape1;
    ModelRenderer Shape2;
    ModelRenderer Shape3;
    ModelRenderer Shape4;
    ModelRenderer Shape5;
    ModelRenderer Shape6;
    ModelRenderer Shape7;
    ModelRenderer Shape8;
    ModelRenderer Shape9;
    ModelRenderer Shape10;
    ModelRenderer Shape11;
    ModelRenderer Shape12;
    ModelRenderer Shape13;
    ModelRenderer Shape14;
    ModelRenderer Shape15;
    ModelRenderer Shape16;
    ModelRenderer Shape17;
    ModelRenderer Shape18;
    ModelRenderer Shape19;
    ModelRenderer Shape20;
  
  public ModelHelicopter()
  {
    textureWidth = 128;
    textureHeight = 64;
    
      Shape1 = new ModelRenderer(this, 0, 0);
      Shape1.addBox(-5F, 0F, -7F, 10, 7, 7);
      Shape1.setRotationPoint(0F, 13F, 0F);
      Shape1.setTextureSize(128, 64);
      Shape1.mirror = true;
      setRotation(Shape1, 0F, 0F, 0F);
      Shape2 = new ModelRenderer(this, 0, 0);
      Shape2.addBox(0F, 0F, 0F, 5, 7, 4);
      Shape2.setRotationPoint(-5F, 13F, 0F);
      Shape2.setTextureSize(128, 64);
      Shape2.mirror = true;
      setRotation(Shape2, 0F, 0.7853982F, 0F);
      Shape3 = new ModelRenderer(this, 0, 0);
      Shape3.addBox(-5F, 0F, 0F, 5, 7, 4);
      Shape3.setRotationPoint(5F, 13F, 0F);
      Shape3.setTextureSize(128, 64);
      Shape3.mirror = true;
      setRotation(Shape3, 0F, -0.7853982F, 0F);
      Shape4 = new ModelRenderer(this, 0, 0);
      Shape4.addBox(-2.5F, 0F, 0F, 5, 7, 5);
      Shape4.setRotationPoint(0F, 13F, 0F);
      Shape4.setTextureSize(128, 64);
      Shape4.mirror = true;
      setRotation(Shape4, 0F, 0F, 0F);
      Shape5 = new ModelRenderer(this, 0, 0);
      Shape5.addBox(-2.5F, 0F, 0F, 5, 3, 3);
      Shape5.setRotationPoint(0F, 13F, 5F);
      Shape5.setTextureSize(128, 64);
      Shape5.mirror = true;
      setRotation(Shape5, -0.7853982F, 0F, 0F);
      Shape6 = new ModelRenderer(this, 0, 0);
      Shape6.addBox(-0.5F, -0.5F, 0F, 1, 1, 6);
      Shape6.setRotationPoint(0F, 19F, 4F);
      Shape6.setTextureSize(128, 64);
      Shape6.mirror = true;
      setRotation(Shape6, 0.4363323F, 0F, 0F);
      Shape7 = new ModelRenderer(this, 0, 46);
      Shape7.addBox(-1F, -1F, 0F, 2, 2, 16);
      Shape7.setRotationPoint(0F, 16F, 4F);
      Shape7.setTextureSize(128, 64);
      Shape7.mirror = true;
      setRotation(Shape7, 0F, 0F, 0F);
      Shape8 = new ModelRenderer(this, 88, 0);
      Shape8.addBox(0F, -0.5F, -0.5F, 3, 1, 1);
      Shape8.setRotationPoint(0F, 14F, 22F);
      Shape8.setTextureSize(128, 64);
      Shape8.mirror = true;
      setRotation(Shape8, 0F, 0F, 0F);
      Shape9 = new ModelRenderer(this, 118, 0);
      Shape9.addBox(0F, -0.5F, 0F, 0, 1, 5);
      Shape9.setRotationPoint(3F, 14F, 22F);
      Shape9.setTextureSize(128, 64);
      Shape9.mirror = true;
      setRotation(Shape9, 0F, 0F, 0.2617994F);
      Shape10 = new ModelRenderer(this, 118, 0);
      Shape10.addBox(0F, 0F, 0F, 0, 1, 5);
      Shape10.setRotationPoint(3F, 14F, 22F);
      Shape10.setTextureSize(128, 64);
      Shape10.mirror = true;
      setRotation(Shape10, 0F, 3.141593F, 0.2617994F);
      Shape11 = new ModelRenderer(this, 0, 0);
      Shape11.addBox(-5F, 0F, -4F, 10, 3, 4);
      Shape11.setRotationPoint(0F, 17F, -7F);
      Shape11.setTextureSize(128, 64);
      Shape11.mirror = true;
      setRotation(Shape11, 0F, 0F, 0F);
      Shape12 = new ModelRenderer(this, 100, 56);
      Shape12.addBox(-5F, 0F, -4F, 10, 4, 4);
      Shape12.setRotationPoint(0F, 13F, -7F);
      Shape12.setTextureSize(128, 64);
      Shape12.mirror = true;
      setRotation(Shape12, 0F, 0F, 0F);
      Shape13 = new ModelRenderer(this, 0, 0);
      Shape13.addBox(-4F, -1F, -1F, 8, 2, 1);
      Shape13.setRotationPoint(0F, 18F, -11F);
      Shape13.setTextureSize(128, 64);
      Shape13.mirror = true;
      setRotation(Shape13, 0F, 0F, 0F);
      Shape14 = new ModelRenderer(this, 0, 0);
      Shape14.addBox(-3F, 0F, 0F, 6, 1, 4);
      Shape14.setRotationPoint(0F, 12.5F, -6F);
      Shape14.setTextureSize(128, 64);
      Shape14.mirror = true;
      setRotation(Shape14, 0F, 0F, 0F);
      Shape15 = new ModelRenderer(this, 0, 47);
      Shape15.addBox(-1F, -1F, 0F, 2, 2, 16);
      Shape15.setRotationPoint(0F, 16F, 4F);
      Shape15.setTextureSize(128, 64);
      Shape15.mirror = true;
      setRotation(Shape15, 0F, 0F, 0.5235988F);
      Shape16 = new ModelRenderer(this, 0, 46);
      Shape16.addBox(-1F, -1F, 0F, 2, 2, 16);
      Shape16.setRotationPoint(0F, 16F, 4F);
      Shape16.setTextureSize(128, 64);
      Shape16.mirror = true;
      setRotation(Shape16, 0F, 0F, 1.047198F);
      Shape17 = new ModelRenderer(this, 0, 40);
      Shape17.addBox(-1F, -1F, -1F, 2, 2, 5);
      Shape17.setRotationPoint(0F, 16F, 20F);
      Shape17.setTextureSize(128, 64);
      Shape17.mirror = true;
      setRotation(Shape17, 0.7853982F, 0F, 0F);
      Shape18 = new ModelRenderer(this, 66, 0);
      Shape18.addBox(-0.5F, 0F, -0.5F, 1, 2, 1);
      Shape18.setRotationPoint(0F, 13F, -4F);
      Shape18.setTextureSize(128, 64);
      Shape18.mirror = true;
      setRotation(Shape18, 3.141593F, 0F, 0F);
      Shape19 = new ModelRenderer(this, 66, 0);//blade
      Shape19.addBox(0F, 0F, 0F, 2, 0, 15);
      Shape19.setRotationPoint(-0.5F, 11F, -4F);
      Shape19.setTextureSize(128, 64);
      Shape19.mirror = true;
      setRotation(Shape19, bladerotater, 0F, 0f);
      Shape20 = new ModelRenderer(this, 66, 0);//blade
      Shape20.addBox(0F, 0F, 0F, 2, 0, 15);
      Shape20.setRotationPoint(0F, 11F, -4F);
      Shape20.setTextureSize(128, 64);
      Shape20.mirror = true;
      setRotation(Shape20, bladerotater, 3.141593F, 0.0f);
  }
  
  private int bladerotater = 0;
  
  public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  {
    super.render(entity, f, f1, f2, f3, f4, f5);
    setRotationAngles(f, f1, f2, f3, f4, f5,entity);
    Shape1.render(f5);
    Shape2.render(f5);
    Shape3.render(f5);
    Shape4.render(f5);
    Shape5.render(f5);
    Shape6.render(f5);
    Shape7.render(f5);
    Shape8.render(f5);
    Shape9.render(f5);
    Shape10.render(f5);
    Shape11.render(f5);
    Shape12.render(f5);
    Shape13.render(f5);
    Shape14.render(f5);
    Shape15.render(f5);
    Shape16.render(f5);
    Shape17.render(f5);
    Shape18.render(f5);
    Shape19.render(f5);
    Shape20.render(f5);
  }
  
  
  
  private void setRotation(ModelRenderer model, float x, float y, float z)
  {
    model.rotateAngleX = x;
    model.rotateAngleY = y;
    model.rotateAngleZ = z;
  }
  
  public void setRotationAngles(float par1, float par2, float par3, float par4, float par5, float par6, Entity par7Entity)
  {
    

      
  

}

 

Link to comment
Share on other sites

use SetRotationAngles for this.

 

just do something like this in that methode:

this.shape.rotateAngleZ = 2.0F

 

You might wanna look into this section of the class.

just take a look at the ModelBiped.class and you'll figure it out!

 

The problem is the code you gave example for would only keep the blades at a fixed rotation.  To make the blades rotate, you want some method to know how many ticks have gone by.  You can do this with a custom counter (just count each render) or you can use the ticksExisted() method for the entity passed to the render.  I usually use the ticksExisted.

 

For pure rotation (like this case) you can probably just use a += to increase the angle each time but in the general case an animation needs some sense of time elapsed.

 

Note also that if you want the rotor to stop sometimes (like if the helicopter can land) then you'll need some boolean field or test to control the rotation -- i.e. only rotate if you know it is supposed to.

 

Anyway, my point is that for it to actually rotate you need to change the rotation in each render pass and that means you need some sense of progression via a counter or some sort.

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

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.