#know which part of an entity I've interacted with

1 messages · Page 1 of 1 (latest)

stone tide
#

I have an entity (big square) and I want to know which part of the entity (the three different partitions) i actually clicked on.

Preferably before the interaction occurs (so I can change the interaction text for mobile), but I'm fine with after as well.
The entity is always fixed to this block, so no rotational stuff needs to be taken into account.

I saw there are RaycastHit and similar classes in the API, I can't seem to find how to use them. Same for the PlayerInteractWithEntityAfterEvent - i can see it's there, but I can't see how I get it. Plus maybe that doesn't even help 😄

I used a java picture for illustration, I'm in bedrock.

earnest sage
#

need to use another entity

#

scripts can't do that only in blocks.

#

and blocks only hav 16x16x16 size

late epoch
#

if they did the math manually with their view direction they could theoretically make it possible

#

but it would be overly complicated and likely not worth it

stone tide
#

since the entity is blockaligned, can't i use the block method to figure it out? Or do I need to interact with a block for that to work? @earnest sage

#

And how does the block option work?

earnest sage
earnest sage
#

1 full block?

stone tide
#

it's not intended to be a full block, no.

#

about 0.75 of a block

#

also, is block interaction out of experimental yet?

formal river
#

Actually you can use viewdirection to see where the player is looking at the block then test if the player interacted with the entity

formal river
earnest sage
stone tide
#

view direction and position I guess? whelp, I guess that's what I need to do then 😅

formal river
stone tide
#

so, the answer seems to be "do the math yourself". alright then, this shouldn't be too hard tbh.

bold temple
#

there is a precise interaction tutorial on wiki.bedrock.dev you can see

stone tide
#

alright, I didn't actually need to do any math after all, thanks to player.getBlockFromViewDirection() returning a block object that includes a faceLocation attribute that just gives me the position on the face of the block that I'm looking at. And since the entity is aligned with the block, it's a simple "is this coordinate within this box" check, no math required.

earnest sage