Posted February 17, 20214 yr Vector3d eyeVec = playerIn.getEyePosition(1.0F); Vector3d lookVec = playerIn.getLook(1.0F); final double distance = 20.0D; Vector3d finVec = eyeVec.add(lookVec.getX() * distance, lookVec.getY() * distance, lookVec.getZ() * distance); AxisAlignedBB axisalignedbb = playerIn.getBoundingBox().expand(lookVec.scale(distance)).grow(1.0D, 1.0D, 1.0D); double d1 = distance * distance; if (Minecraft.getInstance().objectMouseOver != null) { d1 = Minecraft.getInstance().objectMouseOver.getHitVec().squareDistanceTo(eyeVec); } EntityRayTraceResult entityRayTraceResult = ProjectileHelper.rayTraceEntities(playerIn, eyeVec, finVec, axisalignedbb, (p_215312_0_) -> { return !p_215312_0_.isSpectator() && p_215312_0_.canBeCollidedWith(); }, d1); I tried to get the entity beyond the line of sight of playerIn with this code, but I can only get up to about 3 blocks. In the first place, I'm not sure what each argument of rayTraceEntities of ProjectileHelper represents. For example, which parameter should I use to get the entity in the line of sight (within 20 blocks from the player)?
February 17, 20214 yr I think it goes only up to 3 blocks because thats the reach of a regular PlayerEntity, might be wrong though/ I think your question is how to find entities on a line from one Vector3d to another. Now I know this isnt really your question but there is another way to trace entities. You create an AABB (AxisAlignedBoundingBox) starting at your start vector and ending at the end vector and using the world object you are raytracing in you use getEntitiesWithinAABB to get the entities that are in the cube with a vertex at the start vector and the opposite vertex at the end vector. You then iterate over the entities and use Entity#getBoundingBox#rayTrace to check if the entity is on the line. The parameters of AABB are the top corner and the opposite corner. The parameters of getEntitiesWithinAABB are a class object which determines which entities the function is checking for in the bounding box, i.e if you give it ProjectileEntity.class it will only return a list of entities that extend ProjectileEntity, and the bounding box AABB. The parameters of rayTrace are the start and end vector that define the line you are checking for. If you just want to know if a line goes through the boundingBox of an entity entity.getBoundingBox.rayTrace(start, end) should do it. You can also use something like World#getEntitiesWithinAABBExcluding to exclude the shooter. I must say aswell, looking at it now ProjectileHelper#rayTraceEntities seems to do that ^ ish and take the same parameters needed there so hope it explained that too. Hope this was helpful and answered your question Edited February 17, 20214 yr by Iron1601
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.