Jump to content

[1.15.2] Checking if entity or player is looking at another entity


SSilvamc

Recommended Posts

I've seen some ways on how to go about doing this for extended sword reach (checks entities in surrounding AABB, checks if the length of the vector from the player's eye to an entity is within said range, checks the angle, then hits the entity). I found an example of this being applied in the Aether mod's source code (here) which with just a few changes works well in 1.15.2.

The thing is, I was trying to think of another ways to make this work. For instance, I'd like to use the player's eyesight vector and ray trace from there to a certain length (say, 8 blocks' distance) and check if the ray hits an entity's bounding box. This way, I wouldn't need to check all the surrounding entities.

Endermen use the canEntityBeSeen method, and that one draws a vector and checks that it doesn't collide with any blocks. The problem is, this method already knows the position of both the enderman in question and the player.

One option was to use a method found in the Minecraft class, but of course, that would only work client-side.

 

Also, by the way, is there any replacement for onEntitySwing on 1.15.2? I've been using onItemRightClick for now to test, but I want to check for entities using it (so a skeleton, for instance, can use it as a sword). Which method would I have to override?

Link to comment
Share on other sites

bump

Figured I'd use one vector for the player's look, and then a second vector which is a scaling of the first based on the distance I want. This works in order to create a RayTraceResult for blocks, but how would I go about doing this on entities?

Also, is ray tracing only client-side?

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.