I need to create a ray // to the floor, starting from the character, which goes in the direction of the mouse, how could i do that ?
I tried a lot of different stuff, but can’t seem to get it right, for example I can’t do ViewportPointToRay because i’d need the length of this vector to create a ray // to the floor after.
I’m pretty sure you need 3 pieces of information to solve for those unknowns you have (3 sides, 2 sides + angle, or 2 angles + side).
You only have one angle and one side length. But i’m pretty sure your Z at the top can be solved for in Roblox. Are you using Mouse.Hit or something like it (I’ve never used it before). If you can, try to get the mouse position and the character position. Then the length of Z is just
local Z = (CharacterPosition - MousePosition):Magnitude()
I think. That’s assuming I am using the right syntax, please double check it, it’s been a while since I’ve dealt with vectors.
Oh yeah and you use sine law to solve for the remaining sides.
Thanks for your reply, I’m not using mouse.Hit but UserInputService:GetMouseLocation() and ViewportPointToRay. Problem with mouse.Hit.p is that it might not be the exact distance of z.
Example :
So I know the pos of the character and the camera, the direction and length of the vector from the char to the camera and the direction of the vector from the camera to the mouse.
I don’t know the length from that vector, neither the direction/length of the vector // to the floor going from the char to the mouse (and ofc the position of the mouse to create a // vector to the floor)
TLDR : I know the length and direction of C, and the direction of R.
Can you clarify what you are solving for. Also I think you mentioned that mouse.Hit or whatever gives you “Z2” or what I’m writing as Vector “M”, so I’m getting even more confused by that lol
But anyways try out that line segment intersection thing and see if it works.
Lol yes there’s always room to improve in paint in my case.
I’m still going to try and solve it nicely (I saw the post you linked and it seems a little over-aggressive). If I don’t reply to this thread again then I’ve probably lost too many braincells to continue D:
Now I’m going to define C, O, and M as the camera position, character position, and mouse position respectively. Not vectors pointing towards each other.
We need a constant k in order to use the one-liner. That’s because V is horizontal so its y-coordinate is the same as the character’s.
local C = Camera.Position -- wherever you get this from
local O = Character.HumanoidRootPart.Position
local M = Mouse.Position -- wherever you get this from
local k = (O.Position.Y - C.Position.Y)/(M.Position.Y - C.Position.Y)
-- Now the one-liner
local V = C - O + k*(M - C)
-- and if you want the magnitude (distance)
print(V:Magnitude())
@DogPooIEat yeah in retrospect that makes a lot more sense now. I guess I was having too much fun drawing in paint.
Besides, a one-liner is more interesting than having the internals do it for you. I understand if it’s a paragraph of code but this solution is just as short.