Guard Vision Raycasting Cones

Patrolling guards project green laser cones of dust particles that clip dynamically against stone walls and flash red whenever they intersect a moving target.

Java EditionParticle ArtHard24 commandsTested on a real 26.2 & 26.3 server
Two pillager guards emit green particle vision cones while patrolling near a glowing creeper and stone walls. Download the GIF Video & GIF © www.9minecraft.net

Shapes & GeometryTechnologyMedievalGreenRedMini-gameAdventure MapMap MakingRiding & passengersSummoned mobsBlock building (fill/setblock/clone)Rotation math21+ commands

Two patrolling pillager guards sweep the courtyard with seven-beam green laser cones made of glowing dust particles. Whenever a beam hits one of the stone walls, it stops cleanly instead of passing through.

A glowing creeper circles the inner lane in the opposite direction. When a guard's vision cone sweeps past the walls and catches the target in the open, the intersecting beams instantly switch from green to bright red.

1. Setup - type these once 10 commands

  1. /scoreboard objectives add c9age dummy
  2. /scoreboard objectives add c9red dummy
  3. /scoreboard objectives add c9rot dummy
  4. /scoreboard objectives add c9off dummy
  5. /fill ~ ~ ~-1 ~ ~2 ~1 minecraft:polished_deepslate
  6. /fill ~-1 ~ ~5 ~1 ~2 ~5 minecraft:stone_bricks
  7. /summon area_effect_cloud ~-7 ~ ~ {Duration:1,WaitTime:0,Radius:0.0f,Passengers:[{id:"minecraft:pillager",Tags:["c9_guard","c9_g1"],NoAI:1b,Silent:1b,Invulnerable:1b,PersistenceRequired:1b,Rotation:[180.0f,0.0f],equipment:{mainhand:{id:"minecraft:crossbow",count:1}}},{id:"minecraft:marker",Tags:["c9_ray","c9_r1"],data:{off:-210}},{id:"minecraft:marker",Tags:["c9_ray","c9_r1"],data:{off:-140}},{id:"minecraft:marker",Tags:["c9_ray","c9_r1"],data:{off:-70}},{id:"minecraft:marker",Tags:["c9_ray","c9_r1"],data:{off:0}},{id:"minecraft:marker",Tags:["c9_ray","c9_r1"],data:{off:70}},{id:"minecraft:marker",Tags:["c9_ray","c9_r1"],data:{off:140}},{id:"minecraft:marker",Tags:["c9_ray","c9_r1"],data:{off:210}}]}
  8. /summon area_effect_cloud ~7 ~ ~ {Duration:1,WaitTime:0,Radius:0.0f,Passengers:[{id:"minecraft:pillager",Tags:["c9_guard","c9_g2"],NoAI:1b,Silent:1b,Invulnerable:1b,PersistenceRequired:1b,Rotation:[0.0f,0.0f],equipment:{mainhand:{id:"minecraft:crossbow",count:1}}},{id:"minecraft:marker",Tags:["c9_ray","c9_r2"],data:{off:-210}},{id:"minecraft:marker",Tags:["c9_ray","c9_r2"],data:{off:-140}},{id:"minecraft:marker",Tags:["c9_ray","c9_r2"],data:{off:-70}},{id:"minecraft:marker",Tags:["c9_ray","c9_r2"],data:{off:0}},{id:"minecraft:marker",Tags:["c9_ray","c9_r2"],data:{off:70}},{id:"minecraft:marker",Tags:["c9_ray","c9_r2"],data:{off:140}},{id:"minecraft:marker",Tags:["c9_ray","c9_r2"],data:{off:210}}]}
  9. /summon creeper ~-3.5 ~ ~ {Tags:["c9_target"],NoAI:1b,Silent:1b,Invulnerable:1b,PersistenceRequired:1b,Glowing:1b,Rotation:[0.0f,0.0f]}
  10. /execute as @e[tag=c9_ray] store result score @s c9off run data get entity @s data.off

2. Loop - one repeating command block each (Always Active) 14 commands

  1. /execute as @e[tag=c9_guard] at @s positioned ^ ^ ^0.094 run tp @s ~ ~ ~ ~1.2 ~
  2. /execute as @e[tag=c9_target] at @s positioned ^ ^ ^0.147 run tp @s ~ ~ ~ ~-2.4 ~
  3. /scoreboard players add @e[tag=c9_ray] c9age 1
  4. /scoreboard players remove @e[tag=c9_ray,scores={c9red=1..}] c9red 1
  5. /execute as @e[tag=c9_ray,scores={c9age=10..}] run scoreboard players set @s c9age 0
  6. /execute as @e[tag=c9_r1,scores={c9age=0}] at @e[tag=c9_g1,limit=1] run tp @s ~ ~1.5 ~ ~ 0
  7. /execute as @e[tag=c9_r2,scores={c9age=0}] at @e[tag=c9_g2,limit=1] run tp @s ~ ~1.5 ~ ~ 0
  8. /execute as @e[tag=c9_ray,scores={c9age=0}] store result score @s c9rot run data get entity @s Rotation[0] 10
  9. /execute as @e[tag=c9_ray,scores={c9age=0}] run scoreboard players operation @s c9rot += @s c9off
  10. /execute as @e[tag=c9_ray,scores={c9age=0}] store result entity @s Rotation[0] float 0.1 run scoreboard players get @s c9rot
  11. /execute as @e[tag=c9_ray] at @s if block ~ ~ ~ air unless entity @e[tag=c9_target,distance=..1.2] run tp @s ^ ^ ^0.7
  12. /execute as @e[tag=c9_ray] at @s if entity @e[tag=c9_target,distance=..1.4] run scoreboard players set @s c9red 14
  13. /execute as @e[tag=c9_ray] unless score @s c9red matches 1.. at @s if block ~ ~ ~ air run particle dust{color:[0.1,1.0,0.25],scale:1.5} ~ ~ ~ 0.06 0.04 0.06 0 2 force
  14. /execute as @e[tag=c9_ray,scores={c9red=1..}] at @s if block ~ ~ ~ air run particle dust{color:[1.0,0.1,0.1],scale:1.8} ~ ~ ~ 0.08 0.05 0.08 0 3 force

How it works

Frames from the test run

Guard Vision Raycasting Cones - frame 1Guard Vision Raycasting Cones - frame 2Guard Vision Raycasting Cones - frame 3

Recorded on our own test server: 58 frames at about 9.4 fps. Our image check saw: Two pillagers patrol around small stone walls with green particle cones emitting from them, while a glowing creeper walks in the opposite direction.

Commands, video and screenshots: tested and recorded by www.9minecraft.net © 9Minecraft. Sharing a video or screenshot? Please credit www.9minecraft.net.

Build it in your world

  1. Clear a flat open area at least 19x19 blocks wide and stand at the center.
  2. Run the 10 setup commands once in order from chat (or a single-use impulse command block chain) to build the walls, scoreboards, guards, target, and ray markers.
  3. Place 14 repeating command blocks set to Always Active, positioned at or referencing the center of your arena.
  4. Paste each of the 14 loop commands into its own repeating command block so they all run every game tick.
  5. Set the time to night with /time set night so the green and red laser cones stand out clearly.

Use it with real players

To play stealth against the guards yourself, remove the demo creeper with /kill @e[tag=c9_target], delete the second loop command that moves the target, and run /tag @s add c9_target on any player who wants to be detected (or replace @e[tag=c9_target,distance=..1.2] and distance=..1.4 in loop commands 11 and 12 with @a[gamemode=survival]).

Remove it again 9 commands

  1. /kill @e[tag=c9_guard]
  2. /kill @e[tag=c9_target]
  3. /kill @e[tag=c9_ray]
  4. /fill ~ ~ ~-1 ~ ~2 ~1 minecraft:air
  5. /fill ~-1 ~ ~5 ~1 ~2 ~5 minecraft:air
  6. /scoreboard objectives remove c9age
  7. /scoreboard objectives remove c9red
  8. /scoreboard objectives remove c9rot
  9. /scoreboard objectives remove c9off

FAQ

Can I add extra walls or pillars for the laser cones to clip against?

Yes. Any solid block placed in the arena will block the rays because the step and particle commands only run inside <code>air</code> blocks.

How do I change the vision cone length or angle?

To adjust the range, change the <code>0.7</code> step distance in loop command 11 or the <code>10..</code> reset threshold in loop command 5. To widen the cone, edit the <code>off</code> values in setup commands 7 and 8 (in tenths of a degree).

Commands used

/data/execute/fill/particle/scoreboard/summon/tp

Similar creations

Join 9Minecraft News & Guides