#Highlight-able entities

1 messages · Page 1 of 1 (latest)

gilded field
#

I want to be able to highlight specific entities that the player is looking at, i.e.:

  1. I have a text display that I want to change color/become bold or whatever when the player is looking at it
  2. I am going to have a character select area with armor stands showing different characters, with a clickable text display below to select them. I would like the armor stands to be given the glowing effect when the player looks at the text display underneath the armor stand (each one will probably be tagged with the character name)

Probably have this controlled by a "highlightable" tag or something so I can easily add more highlightable stuff down the line if need be

agile vortexBOT
#

<@&1201956957406109788>

Someone will come and help soon!

💬 While you wait, take this time to provide more context and details.

🙇 After a while, hit the Summon Helpers button to ping the helper team. They'll be happy to help you

✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve

ripe fox
#

For that you'd need to do some simple raycasting

stiff jungleBOT
#

Raycast

    >>> # Raycasting Guide

Raycasting is when we shoot a line from the player's eyes in the direction they are looking. We use this to get what the player is looking at, and do something to it, such as spawning an explosion.

Raycasting is very simple. All we need do is run a recursive function. This function will run at the player's eyes, check if there is a block at ~ ~ ~, and if there is not, then move 0.1 blocks forward and run itself again. This creates a loop, which will eventually hit a block.

start_raycast function:

# Set the distance limit on the raycast. (10 x limit in blocks, so 1000 would be 100 blocks)
scoreboard players set .limit <any objective> 1000

# Start the raycast
execute at @s anchored eyes positioned ^ ^ ^.1 run function <namespace>:raycast

raycast function:

# Remove one from the limit
scoreboard players remove .limit <objective> 1

# Optional - place a particle, to make the raycast leave a trail
particle minecraft:dust 1 0 0 1 ~ ~ ~

# If the raycast has hit a block, do something
execute unless block ~ ~ ~ #<namespace>:pass_through run setblock ~ ~ ~ diamond_block

# If the raycast hasn't hit a block, continue, but only if the limit is 1 or more (1..)
execute if block ~ ~ ~ #<namespace>:pass_through positioned ^ ^ ^0.1 if score .limit <objective> matches 1.. run function <namespace>:raycast```

namespace/tags/blocks/**pass_through**.json:```
{
    "replace": false,
    "values": [
        "minecraft:air",
        "minecraft:cave_air",
        "minecraft:void_air"
    ]
}

This should be it! Make sure you add all the functions, and fill in all the blanks (indicated by <this>). Then, you can run the start_raycast function as a player, and it should work.

ripe fox
#

Thank you for saving me time Sila lol

waxen lodge
#

lul no problem

#

that is a guide for raycasting to a block though

ripe fox
#

So in this case instead of checking for a valid block, you'd just check if the highlight-able entity is within a certain distance (or, to be super fancy, use dx,dy,dz target selectors)

#

Though the latter actually probably wouldn't work for text displays as well

urban tusk
waxen lodge
#

does work if you want it to go through tall flowers

urban tusk
waxen lodge
#

i should also add light and structure void tho

urban tusk
waxen lodge
novel hare
#

execute on target moment

#

like litterally why do you need raycasting?

waxen lodge
#

execute on target is the target that the entity intends on attacking

#

so like, the entity another entity is following/attacking

novel hare
#

yes

gilded field
novel hare
#

that's what THUNDERSTONE want

waxen lodge
#

huh?

gilded field
novel hare
gilded field
waxen lodge
#

you don't want to use execute on target. @novel hare, please read the question again

novel hare
gilded field
waxen lodge
#

target doesn't even work for players

waxen lodge
#

but the idea and logic is the same

gilded field
gilded field
#

something like

execute as @e[tag=one_tag, dx=0] positioned ~-0.99 ~-0.99 ~-0.99 if entity @s[dx=0] positioned ~0.99 ~0.99 ~0.99 run function namespace:function1
execute as @e[tag=another_tag, dx=0] positioned ~-0.99 ~-0.99 ~-0.99 if entity @s[dx=0] positioned ~0.99 ~0.99 ~0.99 run function namespace:function2
#

maybe have the differentiation in the function triggered by the raycast collisoin

#

so it's not doing essentially 2 raycasts

waxen lodge
#

so you can check when it hits any entity with a specific tag (give all the entities an overall tag) and run a function, then check the specific tag of the entity in the function

gilded field
#

yeah that's what I was thinking

#

that makes sense

waxen lodge
#

so
hits entity with a tag -> check if it has a specific tag -> apply specific effects

gilded field
#

i feel like that may be inefficient if i end up with a lot of tags i want to test for

#

is there a way to like

#

"return" out of a function

urban tusk
#

yep

#

type return 0

gilded field
#

hmmm

#

well so in the function that runs once the raycast hits an entity

gilded field
#

i would have like

execute if @e[tag=1]...
execute if @e[tag=2]...
execute if @e[tag=3]...
#

i feel like there is a better way to do it

urban tusk
#

just 3 tags?

gilded field
#

probably no more than like

#

20? like way down the line

urban tusk
#

@e is bad, but @s is good, so just keep that in mind

gilded field
#

so checking tags with selector is pretty good for performance

#

oh ok

#

so as long as the collision function executes as the entity that gets hit by the raycast it should be pretty simple

urban tusk
#

right

urban tusk
#

why the raycast too

#

what is your end goal

gilded field
#

i was thinking for the character select each of the buttons would have a tag for the specific character so that it would glow the right armor stand

#

so like uuuuuh

waxen lodge
gilded field
#

hold on

urban tusk
#

i thought you wanna glow the armorstand you're currently looking at

#

no?

gilded field
urban tusk
#

oohk

gilded field
#

so it would be like

if the raycast hits target with tag1 run function for tagA
if the raycast hits target with tag2 run function for tagB
#

or i should say "run effect give the armor stand with tagX glowing"

#

or whatever

urban tusk
#

nono nononons

#

why not just glow the closest armorstand?

#

thats wayyyyyyy more optimized

gilded field
#

genuis

urban tusk
#

selectors have parameter
sort= that could be set to nearest and theres also limit= that could be set to 1 so you only get 1 closest armorstand

gilded field
#

yeah i know

#

oh lord

urban tusk
#

oh. cool, i thought you were new to datapacks

gilded field
#

i am

urban tusk
#

you make command block stuff before?

gilded field
#

but not to commands

urban tusk
#

yea makes sense

gilded field
#

i remember when i had to /give 137

urban tusk
#

oh you're THAT old

gilded field
#

lmao

urban tusk
#

i remember that time as well

#

xd

#

i am not as old tho

gilded field
#

i've been playing since like 1.4 i think

#

i'm 19 i started playing at like 9 or 10

urban tusk
urban tusk
#

that means

#

you're an actual minecraft fan

#

that did commands

#

and now tries datapacks

gilded field
#

yeah i did a similar minigame with command blocks like a year ago

#

but it got to a point where it was a little doodoo

#

and decided to try datapack

urban tusk
#

ok so you have your current struggle / problem

#

is this resolved

gilded field
#

need to set up raycasting and try it

#

a little busy right now though

urban tusk
#

i can sense your familiarity with some real programming languages, am i right?

gilded field
#

i did javascipt for fun here and there. never got much past classes/inheritance and objects and all that

#

i've been adjacent to programming my whole life, i have a degree in cybersecurity

#

never quite got into it though

urban tusk
#

oh

#

cool

gilded field
#

is there a way to pass parameters through a function

#

so when I call a raycast I can pass through a distance value when I call it

#

probably a scoreboard right

waxen lodge
#

macros exist but for this use case that’s not really a good idea

#

you can just set the max score before you run the raycast function

gilded field
#

yeah that's what i was thinking, didn't know if there was a better way or something

waxen lodge
#

you can use macros, so you pass in a NBT compound to the function then whenever you do $(arg) it will replace that with the value you pass in (simplified but that’s the idea)

#

but for this that wouldnt really work

#

you could make a utility function to call the raycast and have that use a macro to set the score but just setting the score before you run the function is easier

gilded field
#

that sounds better for maybe text stuff

#

now i guess another question

#

is there a way to make the armor stands glow for only one player?

gilded field
#

here is everything i have so far also

waxen lodge
#

i might be mistaken but i think you’d do if entity @e[dx=0,dy=0,dz=0]

gilded field
#

i run the start function and nothing happens

#

both looking at and not looking at an entity

waxen lodge
#

the first line in the raycast function could just be execute if entity @e[dx 0,dy=0,dz=0] as @e[dx 0,dy=0,dz=0] run function <collide function>

#

then on the last line you only run the raycast function again UNLESS that entity exists

#

@ripe fox am I correct in it being dx dy dz all equal to 0?

ripe fox
#

No

#

dx,dy,dz create basically a cuboid selection area, with the current executing position being one corner, that finds any entities who's hotboxes intersect any of that cube. So it needs to be a nonzero value

#

This is different from using distance as that only finds entities who's foot position is within the radius

ripe fox
#

Generally you also do need to define all 3 for them to work

gilded field
#

or do 0.01 for all 6

#

or do half negative?

ripe fox
#

Again, they need to be nonzero

gilded field
#

so all 0.01?

ripe fox
#

Yes, but the if entity check you have there isnt necessary

#

Just do the as part

gilded field
#

it runs, detecting me now though

ripe fox
#

What you're doing right now is checking if the entity is there twice (once to see if it's there and once to run the function. That's not necessary, because if there isn't an entity there then of course, it won't run the function as it anyway

gilded field
#

add the raycast_exempt tag to the selector?

ripe fox
gilded field
#

it's detecting me

ripe fox
#

Indeed

#

You're an entity

gilded field
#

yeah i have the raycast_exempt tag added to the entity that runs the raycast function

ripe fox
#

Then that would be a way to do it, yes

gilded field
#

got it

ripe fox
#

That would be excluding certain entities. The other option is to have more specific target selectors that don't include those entities

gilded field
#

it works

ripe fox
#

Either is fine and any given use case may prefer one or even both

gilded field
ripe fox
#

Yooo

#

Now, game crash question

#

What happens if it misses?

gilded field
#

nothing

ripe fox
#

Perfect

gilded field
#

distance limit seems to work

#

could i now replace this first line with

execute as @s run say hit

?

#

because i think the collision function is run as the entity being hit and that should be more efficient

#

well i guess i could just try it lol

#

yep

#

also is there a way to change the length of an interaction entity

#

i can change width and height but not length

ripe fox
gilded field
#

damn

agile vortexBOT
# gilded field distance limit seems to work
🎗️ Is your question resolved?

If your question is resolved, that's great to hear! Make sure to run /resolve or click the Resolve Question button. Otherwise, feel free to continue asking for help! :D

gilded field
#

detecting armor stand way off for some reason

ripe fox
#

Take the same screenshot but with F3 mode please

gilded field
#

hitbox is here

ripe fox
#

Yeah, as expected

#

So it's because dx,dy,dz use the executing position as the negative corner of the cuboid. In this orientation then, the cube is not centered on your line of sight but actually extends up and out to the left, in the positive x,y,z directions. So, even though you're not looking directly at the armor stand, it's within the cuboid target selector

#

This can be mitigated with either smaller dx,dy,dz arguments, or offsetting the exectuing position first with a positioned ~-x ~-x ~-x command argument

gilded field
#

this line?

ripe fox
#

Yeah, but I am pretty confident those also should not be 0s.

gilded field
#

wait maybe i forgot to change them

#

i thought i did but i guess not

ripe fox
#

I guess if it's working then you can ignore me, but it seems like it's not and that may be part of the problem, if not the entire problem

gilded field
#

yeah no it's not

#

i tried setting each to 0.01, it does the same thing

ripe fox
#

Hmm that does seem pretty small

urban tusk
ripe fox
#

So it may be an issue elsewhere in your raycast

waxen lodge
#

i assumed dxyz=0 meant the cuboid wasnt a cuboid and just a single point so it’d get any entities whos hitboxes contain the point

#

if not 0.1 should work

#

i dunno much about dxyz tho

gilded field
urban tusk
#

dxyz=0 is 1 block i am telling you, and when dxyz is 1 it becomes 2 blocks

gilded field
#

so set it to -0.99?

urban tusk
#

whatever guys, believe what you want, you can test it yourselves

ripe fox
#

It's incredibly accurate and if it worked that way, it just wouldn't be

urban tusk
#

i have mc opened rn

waxen lodge
ripe fox
waxen lodge
#

i’ve never used this before so im just guessing mostly lol

urban tusk
#

guess what? we're 1 block away and dxyz is exactly 1 block as i told you.

ripe fox
# gilded field this is all my code

Anyway, unfortunately @gilded field I'm not really seeing anything there that would cause the behavior you're experiencing at a glance 🤔

waxen lodge
gilded field
#

yeah the smoke appears in a line just fine

urban tusk
#

raycast exempt

gilded field
#

to exclude the player executing the raycast

#

since it starts at the camera

urban tusk
#

ohh right

#

sure

#

i usually call this tag self

ripe fox
#

The tag can be applied to many things used in this way

#

So the way that have it named is fine

waxen lodge
#

ok idea

urban tusk
waxen lodge
#

change dxyz=0 to dxyz=0.0, since it might be checking the entire block

urban tusk
gilded field
#

let me see

#

nope

#

still does it

waxen lodge
#

this is very basic but you’re definitley saving the correct file and /reloading, right?

gilded field
#

yep

waxen lodge
#

since that was very fast to check it lol

gilded field
urban tusk
gilded field
waxen lodge
#

this is all very confuzzling

urban tusk
waxen lodge
#

unwise

#

what if they look at their head

#

that’s distance to their feet

gilded field
#

yeah no

#

new gamemode feetshots only

waxen lodge
#

can you zip your datapack rq?

gilded field
#

sure

waxen lodge
#

thats a rar, the bot doesnt like it

gilded field
#

oh uuuuuh

#

hold up

waxen lodge
#

nah i can open that its fine

gilded field
#

ok

waxen lodge
#

i cant see anything wrong from first looks

gilded field
#

i feel like it was working fine yesterday

waxen lodge
#

i cant test it or do much rn bcuz its kinda late and i am tired af

gilded field
#

if i turn around and try on a different entity 180 degrees away from the armor stands, same thing happens but on the left side

#

if i look to the left it still detects

waxen lodge
#

that makes me think that dxyz is counting the full block and not a single point

#

in which case not much can be done

#

but anyway i gotta do a sleep

ripe fox
#

Try offsetting the executing position by -0.5 in the collision command, before the as @e

gilded field
#

uuuuuuuh how

ripe fox
#

Paste the command here if you don't mind

gilded field
#
execute as @e[tag=!raycast_exempt,dx=0,dy=0,dz=0] run function gf:raycast_collide
ripe fox
#
execute positioned ~-0.5 ~-0.5 ~-0.5 as @e[tag=!raycast_exempt,dx=0,dy=0,dz=0] run function gf:raycast_collide
urban tusk
ripe fox
#

??

gilded field
#

only does it about here

ripe fox
#

Right, in theory it should be increasing accuracy, but evidently we're not gonna be able to get it only on the crosshair.

#

Technically, there is one additional mechanism that might make it 100% accurate. I didn't think it would be required

#

You could have the player only run the raycast if they meet a predicate for looking at a valid entity

gilded field
#

i feel like it was perfectly accurate yesterday

ripe fox
#

The reason we didn't just do that from the start is that even with that you would still need a raycast

gilded field
#

when i tested it it was right on the hitbox

ripe fox
#

But, we have to work with the behavior that we're seeing here

gilded field
ripe fox
#

I don't know what to do with that

urban tusk
gilded field
#

right now it's a square on x-z but like 2/3 into a wall

#

it works fine for this use case but i feel like it would restrict for some other thigns

urban tusk
#

yea i dont understand what you wanna change

#

can you point it out

gilded field
#

i don't need the half on the other side of the wall

#

it doesn't affect anything here but

urban tusk
# gilded field

oh right... i am stupid ig but yea not any cuboid shape is allowed idk why did i think that in the first place

#

i can only suggest placing 2 smaller interactions

#

right beside each other

gilded field
#

yeah makes sense

#

more urgent issue the raycast doesn't work anymore

urban tusk
#

wtf

#

did you change anything

gilded field
#

well it worked like yesterday

gilded field
urban tusk
gilded field
urban tusk
#

what dxyz=0 does is creates a area of detecting a entity in 1x1x1 blocks, and what positioned xyz0.5 does is basically aligning that area so that your cursor is in the center of that area

gilded field
#

i want to use this for guns and stuff eventually so i would like it exact

urban tusk
urban tusk
gilded field
gilded field
#

@urban tusk @ripe fox finally got it to work. literally just had to copy what the youtube tutorial i was originally watching said lol

ripe fox
#

Well, glad that works I guess

#

Weird syntaxing

gilded field
#

can you not call functions in tick.mcfunction??

hollow quartz
#

you can

gilded field
#

i have checked /tag @s list and i have the tag

hollow quartz
#

maybe there is an error in the start_raycast function?

gilded field
#

no i can run it manually just fine

urban tusk
#

he forgor at @s and theres no at @s in the raycast_start

hollow quartz
#

oh yeah that ^

gilded field
#

but yeah it works

urban tusk
#

cool

#

this solved then?

agile vortexBOT
# gilded field but yeah it works
🎗️ Is your question resolved?

If your question is resolved, that's great to hear! Make sure to run /resolve or click the Resolve Question button. Otherwise, feel free to continue asking for help! :D

gilded field
#

in a minute

#

gotta do the glowing part

#

and then yeah

gilded field
#

any way to give glowing effect for less than a second?

ripe fox
#

Not currently, you'd need to give it for a second and use some other delay method (schedule or scoreboards) to clear the effect after <20 ticks

gilded field
#

sounds like a way to me

agile vortexBOT
# agile vortex
Question Closed

Your question, #1210635924405231686 (Highlight-able entities), was resolved!

Original Message

#1210635924405231686 message

Duration open

1d12h38m

agile vortexBOT
#
🗑️ Recycling Thread

This thread has been inactive for some time, so I'm going to archive it.

If you're still using the thread, just send a message and it'll pop back on the thread list.