Minecraft - Line of sight detection without raycasting (Eye Sensor)
Line of sight detection without raycasting. No datapacks required this time.
Inspired by
https://www.youtube.com/watch?v=DztEGmf4hrE
World download
https://www.planetminecraft.com/project/line-of-sight-detection/
All my links:
https://heledron.com/links/
Commands
# create scoreboard objectives, call it "lineOfSight.x" and "lineOfSight.y"
# we will use these to store and calculate entity rotations
/scoreboard objectives add lineOfSight.x dummy
/scoreboard objectives add lineOfSight.y dummy
# summon armour stand, call it "lineOfSight.sensor"
/summon minecraft:armor_stand ~ ~1.9 ~ {Tags:["lineOfSight.sensor"], Marker: 1b, Invisible: 1b}
# LOOP: make sensor face away from the player
/execute as @e[tag=lineOfSight.sensor] at @s facing entity @p eyes run tp @s ~ ~ ~ ~180 ~
# LOOP: store player and sensor rotation in scoreboards
/execute as @e[tag=lineOfSight.sensor] store result score @s lineOfSight.x run data get entity @s Rotation[0]
/execute as @e[tag=lineOfSight.sensor] store result score @s lineOfSight.y run data get entity @s Rotation[1]
/execute as @p store result score @s lineOfSight.x run data get entity @s Rotation[0]
/execute as @p store result score @s lineOfSight.y run data get entity @s Rotation[1]
# LOOP: add/subtract player rotation from sensor rotation to find the relative rotation
/scoreboard players operation @e[tag=lineOfSight.sensor] lineOfSight.x -= @p lineOfSight.x
/scoreboard players operation @e[tag=lineOfSight.sensor] lineOfSight.y += @p lineOfSight.y
# LOOP: if the sensor's relative rotation is 0, then the player is looking at it.
# you might want to leave some margin so the rotations don't have to match exactly.
/execute as @e[tag=lineOfSight.sensor] if score @s lineOfSight.x matches -1..1 if score @s lineOfSight.y matches -1..1 run tellraw @a "Hello World!"
Music
C418 - Blind Spots (Minecraft Volume Beta)
https://c418.org/
Build inspirations
"Minecraft: 30+ Laboratory Build Hacks!" by BBlocks
https://www.youtube.com/watch?v=AUfQmAQ7Olg
"Abandoned Lab" by StayCooling
https://www.reddit.com/r/Minecraft/comments/dai29y/forgot_to_post_the_changes_i_did_to_the_abandoned/
#minecraft #commandblock
Gaming