-1

I have these raycast commands and I want to put a range of 6 blocks on it. How can I do it?

execute as @e[dx=0, distance=0.1..] positioned ~-0.99 ~-0.99 ~-0.99 if entity @s[dx=0] run effect give @s instant_damage 1
execute positioned ^ ^ ^1 if block ~ ~ ~ air run function oscar:ray

1 Answer 1

2

How to do it

Set a number equal to how many times the raycast can advance.

Decrease the number each time you advance the raycast 1 block forwards.

When you reach zero, stop advancing the raycast.

In practice

Before you run the raycast function:

scoreboard objectives add count dummy
scoreboard players set #limit count 20

in your raycast function:

scoreboard players remove #limit count 1

at the beginning of this line:

execute positioned ^ ^ ^1 if block ~ ~ ~ air run function oscar:ray 

add:

execute if score #limit count matches 1.. positioned ^ ^ ^1 if block ~ ~ ~ air run function oscar:ray 
2
  • Good idea to have a main function who sets the #limit to 20 and call a secondary function, that shouldn't be called by anything but said main function. This guarantees it will work as it should.
    – BunnyMerz
    Aug 25 at 7:00
  • hello, is this MP compatible?
    – 2wen
    Aug 25 at 7:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .