Hello! I've been trying to use a raycast system to make a vision cone for a mob i am making within a datapack. My raycasting system works perfectly fine at deteing when it hits a block vs when it hits an entity. My problem is that i want the raycast to detect entities in a radius around the ray, not just where the ray hits. Can anyone help me with that. Optionally. if it's possible to actually make it a "cone" (narrower near the entity and the radius getting progressively higher), i would be grateful.
#Vision cone with raycasts
1 messages · Page 1 of 1 (latest)
An actual cone with accurste hit detection is nearly impossible.
You have to make some compromises
i see
one problem i had is that i managed to gen a "cylinde", but it started hitting entities through walls too
- Use a distance selector that increases in size every step of the raycast.
- Use the dx, dy, and dz selector arguments for accurate hit detection but in a square shape
i tried doing this, but it only worked in one way: for instance, it was testing around the ray but only on its right side, not left
- every step of the raycast, shoot 8 rays away from the current position of the original raycast and every step shoot those rays a bit further.
- Shoot 1 ray from the center, like normal and then shoot more rays from the same origin but with a slight angle.
i tried that too but it didn't seem to work.. my rays were getting displaced, like i had a ray shooting diagonally at an angle, but it wasn't placed in the same origin point anymore
that's because you have to offset this imaginary box by half its size to cover your desired area
and i think the 4th option would suit best honestly, but idk what i did wrong
That's weird, if you have a single function that runs multiple raycast functions, they should all start from the same coorinates.
yeah that's what i thought too
i messed a lot with the original code now, but i could show you the same exact raycast code i used for a different creation if it helps
this is a raycast i did for a magic staff for a different map
but i used the same logic for the vision cone
The only thing you have to do for the cone to work is to add a rotation argument to the first images first command and copy it as many times as you need rays.
You can also make it shoot out of the eyey exactly with the anchor subcommand
hmm, i'll have to look into that, since i am not fully experienced with those
i am not an expert in commands, i just have some knowledge haha
and for the roation argument part
i basically need to add one separate command with a different rotation for each individual ray?
i mean, copy paste the first command from the first pic, but with a different rotation each time
yes