#I'm here with your regularly scheduled Raycast Post

5 messages · Page 1 of 1 (latest)

solar ravine
#

Hello! I'm trying to raycast between the players eyes and an entity to see if I have line of sight to them before proceding with another action. I'm working in minecraft 1.19.4 and here is the code I'm using:

Box box = client.cameraEntity.getBoundingBox().stretch(5d,5d,5d);
client.world.getEntities().forEach(entity -> {
            EntityHitResult hitResult = ProjectileUtil.raycast(player, player.getEyePos(), entity.getEyePos(), box, EntityPredicates.VALID_ENTITY.and(checkEntity->!(checkEntity instanceof PlayerEntity)), maxDistanceToTarget);

For a little more context,
the maxDistanceToTarget is set to clientInteractionManager.getReachDistance(), so about 4.5 blocks.
Also I don't totally understand exactly what the bounding box and EntityPredicates are doing at this point as I have copied some of this code from searching the fabric discord.

Right now,
I think the predicates are a filter for a type of entity that intersects the raycast.
I think the bounding box is the area that an entity's hitbox must intersect with during the raycast and that this bounding box is projected along the length of the raycast until it hits the max distance.

Is this an accurate description of the arguments?

When running, every raycast I do returns null. Even if I'm standing in a pit with zombies all around me, no line of sight obstructions, and no other player entities other than my own character.

Any help/advice is greatly appreciated!

#

Oh one last thing, I have extracted this code to a method as I am using it in a few places and now some of my input variables to this raycast method have turned pink and gotten underlined. Intellij doesn't show any problems, but this must have a meaning. Could it be that some of my input parameters for the raycast are null and therefore the raycast also returns null? I'm seeing online that it could be because they are undefined or uninstantiated, but the thing is my method works without the raycast and still returns all entities without checking them to meet the raycast criteria. I will see what I can figure out

regal hawk
solar ravine
solar ravine
#

Going to give a small update, I've rethought my problem a bit here. I don't think I need the entity raycast because I'm not looking for some arbitrary entity in front of my raycast. I'm looking for data about a specific entity (that I know the position of) already in front of my raycast. All I need is a block raycast so I can compare the hitresult vector magnitude to the entity vector magnitude I can calculate. If it's less I hit the block first and I can't see it, if it's more or a miss, I will hit the entity first and I know I have line of sight. My block ray casts have been working fine, so I think this should be better.