Hello fellow Roblox developers.
I am currently in the midst of creating a weapon system for my wizard-type game. The weapons work like any other weapon, using raycasting. But, I am not using Ray.New(), I am using the new (and "Better) worldroot:Raycast().
They work pretty much the same, but some functions are not on the worldroot:Raycast(). But anyways, this is not the important part.
When shooting at someone, you don’t need to hit them exactly. In other words, you can shoot 5 studs to either side of the character and still be awarded points. It’s essentially a bigger hitbox (in a way). But, it’s also for some other reasons that are not important to state here (feel free to ask). So, I think I better show some pictures to describe. I described here also.
So basically I want to get the side distance from a ray to a certain position like so:
Say a ray shoots like this:
I would like to get the distance between the closest point of the ray and the character: (see green marking)
Now, I managed to do something like that:
(Images:
The red part basically finds the closest position, and then you can just do the magnitude between them and you get something like this:
But the harder part is when the ray is at an angle:
Now it will bascially also account for the height change, so the magnitude/Distance will be much greater.
Since now it gets this distance:
But I want this distance:
I just want the distance from the side, if you get what I mean. It’s a little hard to explain, but I did my best.
If you have more questions, please feel free to ask! It would mean the world to me if you guys helped me. Thanks!
Edit:
Thinking about this now, it’s quite easy to exploit. If anyone has other ideas, i’d be more than open to them.