Jump to content

[1.7.10][Solved]Mob's horn tips are a little off


dragon3025

Recommended Posts

This is my mob's rendering code:

 

 

package com.sapphire.mob;

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

public class BullModel extends ModelBase
{
  //fields
    ModelRenderer head;
    ModelRenderer body;
    ModelRenderer leg1;
    ModelRenderer leg2;
    ModelRenderer leg3;
    ModelRenderer leg4;
    ModelRenderer horn1;
    ModelRenderer horn2;
    ModelRenderer horn1point;
    ModelRenderer horn2point;
    
    protected void convertToChild(ModelRenderer parParent, ModelRenderer parChild)
    {
   parChild.rotationPointX -= parParent.rotationPointX;
   parChild.rotationPointY -= parParent.rotationPointY;
   parChild.rotationPointZ -= parParent.rotationPointZ;
   // make rotations relative to parent
   parChild.rotateAngleX -= parParent.rotateAngleX;
   parChild.rotateAngleY -= parParent.rotateAngleY;
   parChild.rotateAngleZ -= parParent.rotateAngleZ;
   // create relationship
       parParent.addChild(parChild);
    }
  
  public BullModel()
  {
    textureWidth = 96;
    textureHeight = 32;
    
    head = new ModelRenderer(this, 0, 0);
    head.addBox(-4F, -4F, -6F, 8, 8, 6);
    head.setRotationPoint(0F, 4F, -8F);
    head.setTextureSize(96, 32);
    head.mirror = true;
    setRotation(head, 0F, 0F, 0F);
    body = new ModelRenderer(this, 20, 4);
    body.addBox(-6F, -10F, -7F, 12, 18, 10);
    body.setRotationPoint(0F, 5F, 2F);
    body.setTextureSize(96, 32);
    body.mirror = true;
    setRotation(body, 1.570796F, 0F, 0F);
    leg1 = new ModelRenderer(this, 0, 16);
    leg1.addBox(-3F, 0F, -2F, 4, 12, 4);
    leg1.setRotationPoint(-3F, 12F, 7F);
    leg1.setTextureSize(96, 32);
    leg1.mirror = true;
    setRotation(leg1, 0F, 0F, 0F);
    leg2 = new ModelRenderer(this, 0, 16);
    leg2.addBox(-1F, 0F, -2F, 4, 12, 4);
    leg2.setRotationPoint(3F, 12F, 7F);
    leg2.setTextureSize(96, 32);
    leg2.mirror = true;
    setRotation(leg2, 0F, 0F, 0F);
    leg3 = new ModelRenderer(this, 0, 16);
    leg3.addBox(-3F, 0F, -3F, 4, 12, 4);
    leg3.setRotationPoint(-3F, 12F, -5F);
    leg3.setTextureSize(96, 32);
    leg3.mirror = true;
    setRotation(leg3, 0F, 0F, 0F);
    leg4 = new ModelRenderer(this, 0, 16);
    leg4.addBox(-1F, 0F, -3F, 4, 12, 4);
    leg4.setRotationPoint(3F, 12F, -5F);
    leg4.setTextureSize(96, 32);
    leg4.mirror = true;
    setRotation(leg4, 0F, 0F, 0F);
    horn1 = new ModelRenderer(this, 65, 0);
    horn1.addBox(-1F, -4F, -1F, 2, 5, 2);
    horn1.setRotationPoint(-4F, 0F, -10F);
    horn1.setTextureSize(96, 32);
    horn1.mirror = true;
    setRotation(horn1, 0F, 0F, -0.3490659F);
    horn2 = new ModelRenderer(this, 74, 0);
    horn2.addBox(-1F, -4F, -1F, 2, 5, 2);
    horn2.setRotationPoint(4F, 0F, -10F);
    horn2.setTextureSize(96, 32);
    horn2.mirror = true;
    setRotation(horn2, 0F, 0F, 0.3490659F);
    horn1point = new ModelRenderer(this, 83, 0);
    horn1point.addBox(0F, -3F, 0F, 1, 4, 1);
    horn1point.setRotationPoint(-6F, -4F, -10.5F);
    horn1point.setTextureSize(96, 32);
    horn1point.mirror = true;
    setRotation(horn1point, 0F, 0F, 0F);
    horn2point = new ModelRenderer(this, 88, 0);
    horn2point.addBox(0F, -3F, 0F, 1, 4, 1);
    horn2point.setRotationPoint(5F, -4F, -10.5F);
    horn2point.setTextureSize(96, 32);
    horn2point.mirror = true;
    setRotation(horn2point, 0F, 0F, 0F);
    convertToChild(horn1, horn1point);
    convertToChild(horn2, horn2point);
    convertToChild(head, horn1);
    convertToChild(head, horn2);
  }
  
  public void render(Entity par1Entity, float par2, float par3, float par4, float par5, float par6, float par7)
  {
    setRotationAngles(par2, par3, par4, par5, par6, par7, par1Entity);
    head.render(par7);
    body.render(par7);
    leg1.render(par7);
    leg2.render(par7);
    leg3.render(par7);
    leg4.render(par7);
    //horn1.render(par7);
    //horn2.render(par7);
    //horn1point.render(par7);
    //horn2point.render(par7);
  }
  
  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)
  {
  this.head.rotateAngleY = par4 / (180F / (float)Math.PI);
  this.head.rotateAngleX = par5 / (170F / (float)Math.PI);
  
  this.leg1.rotateAngleX = MathHelper.cos(par1 * 0.6662F) * 1.4F * par2;
  this.leg1.rotateAngleY = 0.0F;
  this.leg2.rotateAngleX = MathHelper.cos(par1 * 0.6662F + (float)Math.PI) * 1.4F * par2;
  this.leg2.rotateAngleY = 0.0F;
  this.leg3.rotateAngleX = MathHelper.cos(par1 * 0.6662F + (float)Math.PI) * 1.4F * par2;
  this.leg3.rotateAngleY = 0.0F;
  this.leg4.rotateAngleX = MathHelper.cos(par1 * 0.6662F) * 1.4F * par2;
  this.leg4.rotateAngleY = 0.0F;
  }

}

 

I posted images of what it looks like in Minecraft and what it looks like in Techne. The red dots in the Techne picture is where I set the rotation points. I also made sure to use addChild() in reverse order (I attached the tip or the horn to the bottom, and then attached the bottom to the head). How can I fix this?

Bull:

 

635497801014840905.png

 

Bull in Techne:

 

635497698953217504.png

 

Link to comment
Share on other sites

Okay, first of all, in the set rotation and angels method you should not do any rotation of the horns or the horn points.  Once they are made children of the head they should automatically turn with the head -- that is the whole point of making them a child.

 

Basically, what you should do is remove the lines that are rotating the horns and horn tips in the setRotationAndAngles() function.

 

Secondly, you need to make sure they are nicely connected and rotated initially.  The easiest way to do this is to rotate them after they are converted to child.  So when you first make the horns and horn tips, do no rotate them at all.  Just make sure they are connected at right point with right rotation points.  Then do the rotation you want to get the horns looking right.

 

After that they should stay connected and should turn with the head, just by rotating the head.

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

Link to comment
Share on other sites

Okay, first of all, in the set rotation and angels method you should not do any rotation of the horns or the horn points.  Once they are made children of the head they should automatically turn with the head -- that is the whole point of making them a child.

 

Basically, what you should do is remove the lines that are rotating the horns and horn tips in the setRotationAndAngles() function.

 

Secondly, you need to make sure they are nicely connected and rotated initially.  The easiest way to do this is to rotate them after they are converted to child.  So when you first make the horns and horn tips, do no rotate them at all.  Just make sure they are connected at right point with right rotation points.  Then do the rotation you want to get the horns looking right.

 

After that they should stay connected and should turn with the head, just by rotating the head.

Thanks for the reply. I discovered that I copied the wrong model file when I made changes to rotation points, and removed the setRotationAngle parts so it's moving correctly now, the tips are still wrong though. Well the horns are angled correctly, it's just for some reason the tips are shifted away from the head, so the left horn tip is a little more left than it is in the Techne and the right horn tip is a little more right than it is in Techne. I suppose if I move the horns in more in Techne it'll fix it, but I don't understand why its like this.

 

EDIT: I fixed it in Techne by pulling the tips in, I don't understand why it spread out in Minecraft. Thanks for your help. Here's what it looks like now:

In Minecraft

 

635497868457371026.png

 

In Techne

 

635497868460496036.png

 

Link to comment
Share on other sites

the offset happends when you assign the parts as a child

But I'm using this:

protected void convertToChild(ModelRenderer parParent, ModelRenderer parChild)
{
   // move child rotation point to be relative to parent
   parChild.rotationPointX -= parParent.rotationPointX;
   parChild.rotationPointY -= parParent.rotationPointY;
   parChild.rotationPointZ -= parParent.rotationPointZ;
   // make rotations relative to parent
   parChild.rotateAngleX -= parParent.rotateAngleX;
   parChild.rotateAngleY -= parParent.rotateAngleY;
   parChild.rotateAngleZ -= parParent.rotateAngleZ;
   // create relationship
   parParent.addChild(parChild);
}

It shouldn't do it with that code right?

Link to comment
Share on other sites

Why don't you just add the addchilds in the constructor itself, from my own experience it doesn't need a new method for it. You don't have to set the rotation points for childs as they automatically bend along with the assigned part.

I just tried that out right now. I used "//" to cancel changing rotation points when using convertToChild and then used "//" to cancel out setting rotation points in the constructor, but it didn't work the Bulls horn's were in the back of it's head. I then used "//" to cancel changing the rotation angles when using convertToChild, but it still looked messed up.

Link to comment
Share on other sites

this.[insert model main part here].addChild( [insert your model part here] );

I was pretty sure what I did would would of gave the same results as this, but just to make sure I tried this anyway. I removed the whole convertToChild part, deleted setting rotation points for the child objects, then used addChild to attach the horn tips to the horn bottoms then used addChild to attach the horn bottoms to the head. The bull still had horns on the back of it's head pointing into the head.
Link to comment
Share on other sites

It's really quite simple, but you need to do things in order and you need to double check rotation points and offsets.

 

The most common mistake is that in Techne (or Java model) you can mistakenly use offsets to make it look like the parts are correctly connected, but you really need to make sure the rotation points are correct (usually at the point of connection between parts).

 

In my tutorial where I introduce the concept of convertToChild() I also talk about the spinX(), spinY(), and spinZ() utility functions for testing your rotation points.  Basically if you take a part and spin it it is the best way to confirm that your rotation points are correct. 

 

From the description of your problem, the rotation points for your horns is still incorrect.  Once the horns are children of the head, the rotation point needs to be *relative* to rotation point of the head.  So if the head rotation point is in the center of the head it will be different than if the rotation point is at the neck connection.  It should be very easy to get it right if you think carefully about it -- you can even just sketch it on paper and do the calculations.

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

Link to comment
Share on other sites

Doesn't this part make it relative though?

	   parChild.rotationPointX -= parParent.rotationPointX;
   parChild.rotationPointY -= parParent.rotationPointY;
   parChild.rotationPointZ -= parParent.rotationPointZ;
   // make rotations relative to parent
   parChild.rotateAngleX -= parParent.rotateAngleX;
   parChild.rotateAngleY -= parParent.rotateAngleY;
   parChild.rotateAngleZ -= parParent.rotateAngleZ;

In Techne I paid attention to the difference between offsets and rotation points. I could see that the blue sphere is the rotation point. When I first tried it, the bottom horn's blue sphere is connected to the head and the horn tip's blue sphere is connected to the horn, but horn tips were way off in Minecraft. When I moved their rotation points (the blue spheres) in Techne so they were more inward and barley touching the horns, that fixed it. I don't know why their tips are moved outward unless the code I posted above isn't setting the relative position right. I got the tutorial from here: http://jabelarminecraft.blogspot.com/p/converting-techne-models-into.html , I did a search (Ctrl+F) and can't find the word "spin" on that page. Where's this spin function?

Link to comment
Share on other sites

Ive been learning mob animations myself recently and have been using the same code.  BTW thanks Jabelar for that and your tutorials, very useful. 

 

I think and I could be wrong, that the code sets the proper rotation angles of the child, but the actual rotation point locations need to be adjusted as well to offset now from the parent instead of the normal offset.    Its a bit complicated, maybe I'm explaining it wrong.

Link to comment
Share on other sites

Ive been learning mob animations myself recently and have been using the same code.  BTW thanks Jabelar for that and your tutorials, very useful. 

 

I think and I could be wrong, that the code sets the proper rotation angles of the child, but the actual rotation point locations need to be adjusted as well to offset now from the parent instead of the normal offset.    Its a bit complicated, maybe I'm explaining it wrong.

Okay, I think I get it now. There were minor offsets, maybe they added up in the end. I'll pay attention to that the next time I make a model.
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.



×
×
  • Create New...

Important Information

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