Created
June 30, 2018 17:12
-
-
Save Corosauce/46ee07b8ed9fecff76a93a0ecd76263a to your computer and use it in GitHub Desktop.
clean example of spin entity around other entity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (ent instanceof EntityPlayer) { | |
EntityPlayer player = (EntityPlayer) ent; | |
List<EntityLivingBase> ents = ent.world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(ent.getPosition()).grow(10, 10, 10)); | |
for (Entity entToSpin : ents) { | |
//get the vector of x and z | |
double vecX = player.posX - entToSpin.posX; | |
double vecZ = player.posZ - entToSpin.posZ; | |
//atan2 will give you the angle for yaw, for how minecraft works this will be 90 degrees off from an angle that will aim it directly at center entity | |
float yawDegrees = (float)(Math.toDegrees(Math.atan2(vecZ, vecX))); | |
//make the spin a bit tighter around the center entity, subtracting a full 90 degrees pulls it right towards you | |
yawDegrees -= 10; | |
float speed = 0.2F; | |
entToSpin.motionX += -Math.sin(Math.toRadians(yawDegrees)) * speed; | |
entToSpin.motionZ += Math.cos(Math.toRadians(yawDegrees)) * speed; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment