Jump to content

[1.7.10] unable to rotate Yaw Entity [HELP]


zedblade

Recommended Posts

Hello,

 

I notice that is inpossible rotate the yaw attribute of any entities setted always to 0:

 

I tried this code but doesn't works:

 

    			EntityCreeper Creeper = new EntityCreeper(player.worldObj);
	    		Creeper.setLocationAndAngles(event.x + 0.5D, event.y, event.z + 0.5D, fYaw, 0.0F);
		    	player.worldObj.spawnEntityInWorld(Creeper );
		    	Creeper.setPositionAndRotation(event.x + 0.5D, event.y, event.z + 0.5D, fYaw, 0.0F);
		    	Creeper.rotationYaw = fYaw;
		    	Creeper.setAngles(fYaw, 0.0F);

 

please help ...

Link to comment
Share on other sites

We need to see more of your code. I see that you set the rotation yaw to fyaw but I don't know what fyaw is set to elsewhere in your code...

 

The Code into "onBreakBlock(BreakEvent event)" function (with "@SubscribeEvent" tag):

 

fYaw = 90.0F;
EntityCreeper Creeper = new EntityCreeper(player.worldObj);
Creeper.setLocationAndAngles(event.x + 0.5D, event.y, event.z + 0.5D, fYaw, 0.0F);
player.worldObj.spawnEntityInWorld(Creeper);
Creeper.setPositionAndRotation(event.x + 0.5D, event.y, event.z + 0.5D, fYaw, 0.0F);
Creeper.rotationYaw = fYaw;
Creeper.setAngles(fYaw, 0.0F);
//Creeper.setRotationYawHead(fYaw); <=== Works but rotate head only 

Link to comment
Share on other sites

The setAngles() method isn't doing what you think it is. Here is the text that the forge gives for what that method does.

 

Adds par1*0.15 to the entity's yaw, and *subtracts* par2*0.15 from the pitch. Clamps pitch from -90 to 90. Both arguments in degrees.

 

try removing that method and see if your entity rotates how you think it should. I tried a test using myself as the entity and when I changed the rotationYaw variable by itself it did work without any added code so try only changing that variable. Also try david's suggestion.

Link to comment
Share on other sites

Spawn the entity after you change all the variables. Make sure it only spawns serverside with if (!player.worldObj.isRemote).

 

Well, I tried this code in creative mode for watch better the creeper movements and not in "paceful" mode, obviously:

 

@SubscribeEvent
public void onBreakBlock(BreakEvent event) {
     		if (!player.worldObj.isRemote) {
                                fYaw = 90.0F; // or = 270.0F or = 180.0F
    			 EntityCreeper Logger = new EntityCreeper(player.worldObj);
	     		Logger.setLocationAndAngles(event.x + 0.5D, event.y, event.z + 0.5D, fYaw, 0.0F);
	     		Logger.rotationYaw = fYaw;            //   <===== Tried With and WithOut this line
		     	player.worldObj.spawnEntityInWorld(Logger);
                         }
           }

 

Results same problem: the Creeper spawn allways with the same Yaw direction (0.0F). :(

 

The setAngles() method isn't doing what you think it is. Here is the text that the forge gives for what that method does.

 

Adds par1*0.15 to the entity's yaw, and *subtracts* par2*0.15 from the pitch. Clamps pitch from -90 to 90. Both arguments in degrees.

 

try removing that method and see if your entity rotates how you think it should. I tried a test using myself as the entity and when I changed the rotationYaw variable by itself it did work without any added code so try only changing that variable. Also try david's suggestion.

 

Seriously, I tried all code combinations but nothing to do ... Can I see your testing code?

 

thank you so much ...

Link to comment
Share on other sites

here is the code that worked for me...

@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack item){
	int yaw = ((int) player.rotationYaw)%360;
	if (yaw<0) yaw+=360;
	if (315<yaw || yaw<=45) world.setBlockMetadataWithNotify(x, y, z, 2, 3);
	if (45<yaw && yaw<=135) world.setBlockMetadataWithNotify(x, y, z, 5, 3);
	if (135<yaw && yaw<=225) world.setBlockMetadataWithNotify(x, y, z, 3, 3);
	if (225<yaw && yaw<=315) world.setBlockMetadataWithNotify(x, y, z, 4, 3);
	player.rotationYaw = 90;
}

the other code you see there just rotates the block depending on which direction you are facing which is unimportant in this case. What is important is the last line player.rotationYaw = 90; when run and I place the block my character is rotated to the position of 90 degrees so it is working for me.

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.