Jump to content

Somes troubles with Minecraft vectors (Again!)


Morteboule

Recommended Posts

Hi everyone,

I'm working on a FOV sight for mobs but i'm in trouble with minecraft vectors.

I triyed to made a vector from where the mob is looking at (with rotationYaw et rotationYawHead) to the mob

and another one from the player to the mob (this one works great)

But with the first vector when i apply a dotProduct i think the vector is not: (Where the mob looking at/ mob) but more: (position of world 0,0,0, / mob) my dot Product reach ~1 when i move the player between the mob and the coord 0,0,0 no matter wich value rotationYaw is (or YawHead).

 

Here is my code:

 

    public void onLivingUpdate()
    {
    	
    	System.out.println("ANGLE YAW:" + this.rotationYaw);
    	System.out.println("ANGLE YAWHEAD:" + this.rotationYawHead);
    	
        float f1;
        float f2;
        float f3;
        float f4;

               f1 = MathHelper.cos(-this.rotationYawHead * 0.017453292F);
               f2 = MathHelper.sin(-this.rotationYawHead * 0.017453292F);
               f3 = -MathHelper.cos(-this.rotationPitch * 0.017453292F);
               f4 = MathHelper.sin(-this.rotationPitch * 0.017453292F);

               Vec3 vecSight = this.worldObj.getWorldVec3Pool().getVecFromPool((double)f2 * f3, (double)f4, (double)(f1 * f3)); 
               Vec3 vecMob = this.getPosition(1.0F);

               Vec3 vec2 = normalize(subtract(vecSight, vecMob));
            
    	Minecraft mc = Minecraft.getMinecraft();
        	EntityPlayer player = mc.thePlayer;

        	Vec3 vecPlayer = player.getPosition(1.0F);
        	
        	Vec3 vec1 = normalize(subtract(vecPlayer, vecMob));
        	
        	 double dp = dotProduct(vec1, vec2);
        	 System.out.println("DP : " + dp);
        	
        	
        	 
        	 if(dp > 1.0F - 0.5F)
        	 {
        		 System.out.println("SEE YOU");
        	 }
    	
        super.onLivingUpdate();
    }

 

I know it's a mess but it's for debugging :)

 

Thanks for help!

 

 

EDIT: Probleme solved juste forgot the mob position before rotationYaw ! Sorry :D

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.