Jump to content

Automatic Aiming Stutter


FreakzBoy

Recommended Posts

Hello, i was working on my minecraft client trying to make an automatic entity facing module and it works perfectly fine. The only problem that is bothering me is that there are stutters in between the yaw updating of the player which I don't know the reason to. The code is from this youtube video:  Facing smoothly

 

Here is a clip of it ingame to understand my problem more easily: Facing Stuttery (My version)

 

It's a bit strange, since for the guy in the video its running smoothly.

 

Here's the code:

 

	@EventTarget
	public void update(EventUpdate e) {
		
		
		ticks1 += 1;
		
		for(Iterator<Object> entities = mc.theWorld.loadedEntityList.iterator(); entities.hasNext();) {
            Object theObject = entities.next();
            if(theObject instanceof EntityLivingBase) {
	                EntityLivingBase entityplayer = (EntityLivingBase) theObject;
	               
	            if(entityplayer.getName() == mc.thePlayer.getName()){
	                continue;
	            }
	            
	            if(entityplayer instanceof EntityPig) {
	            
	            	if(mc.thePlayer.getDistanceSqToEntity(entityplayer) <= 10F) {
	            		
	            		this.faceEntity(entityplayer);
	            	}
	            		
	            }
            
            }	
		}
		
		
	}
	
	public static float[] getRotationsNeeded(Entity entity)
    {
        if(entity == null)
            return null;
        double diffX = entity.posX - Minecraft.getMinecraft().thePlayer.posX;
        double diffY;
        if(entity instanceof EntityLivingBase)
        {
            EntityLivingBase entityLivingBase = (EntityLivingBase)entity;
            diffY =
                entityLivingBase.posY
                    + entityLivingBase.getEyeHeight()
                    * 0.9
                    - (Minecraft.getMinecraft().thePlayer.posY + Minecraft
                        .getMinecraft().thePlayer.getEyeHeight());
        }else
            diffY =
                (entity.boundingBox.minY + entity.boundingBox.maxY)
                    / 2.0D
                    - (Minecraft.getMinecraft().thePlayer.posY + Minecraft
                        .getMinecraft().thePlayer.getEyeHeight());
        double diffZ = entity.posZ - Minecraft.getMinecraft().thePlayer.posZ;
        double dist = MathHelper.sqrt_double(diffX * diffX + diffZ * diffZ);
        float yaw =
            (float)(Math.atan2(diffZ, diffX) * 180.0 / Math.PI) - 90.0F;
        float pitch = (float)-(Math.atan2(diffY, dist) * 180.0 / Math.PI);
        return new float[]{
            Minecraft.getMinecraft().thePlayer.prevCameraYaw
                + MathHelper.wrapAngleTo180_float(yaw
                    - Minecraft.getMinecraft().thePlayer.prevCameraYaw),
            Minecraft.getMinecraft().thePlayer.rotationPitch
                + MathHelper.wrapAngleTo180_float(pitch
                    - Minecraft.getMinecraft().thePlayer.rotationPitch)};
       
    }
   
    public static void faceEntity(EntityLivingBase entity)
      {
    	float[] rotations = getRotationsNeeded(entity);
        if (rotations != null)
        {
            Minecraft.getMinecraft().thePlayer.rotationYaw = rotations[0];
            Minecraft.getMinecraft().thePlayer.rotationPitch = rotations[1] + 1;
        }
    }

 

I would really appreciate it if someone would help me out with my problem!

The person that will help me gets a cookie ?

 

Best Regards,

Freakz :)

Link to comment
Share on other sites

You aren't properly handling "partial ticks." Remember, ticks (game processing) are 20 times per second, but the rendering can be anywhere from 30 to 120 times a second.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

1 minute ago, Draco18s said:

You aren't properly handling "partial ticks." Remember, ticks (game processing) are 20 times per second, but the rendering can be anywhere from 30 to 120 times a second.

Thank you for your quick response, so the reason regarding to the stutter, is my update() method with the EventUpdate e that is calling my faceEntity only 20 times a second?

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.