New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

How does Ray.new(Origin, Direction) work?

Asked by
Psudar 641 Moderation Voter
3 months ago
Edited 3 months ago

I noticed something a little peculiar about Ray.new() and I was wondering if anyone knew why.

I wanted to create a ray cast from one cube to another cube, so I simply inputted the Origin and Direction like this:

local rayCast = Ray.new(Cube.Position, targetCube.Position) 

I thought it would be like a CFrame.new(Position, LookAt) type deal, but I found that the ray cast was firing at an angle instead of directly in the direction of the target.

I checked out the API and found this bit of code and applied it to my own ray cast

local rayCast = Ray.new(Cube.Position, (targetCube.Position - Cube.Position).Unit * 300)

Why does this directly target the cube, as opposed to my first attempt where it shot out at an angle?

Thanks.

0
Oh, and for reference, the cubes are just directly across from each other. I don't think that requires any type of visual representation.  Psudar 641 — 3mo
1
Unit vectors always have a magnitude of 1, so it's just going into the direction specified 300 studs User#24403 0 — 3mo
0
Hey thanks, could you elaborate or send some kinda of resource where I could learn a bit more about Unit Vectors? I honestly didn't know that and still have a bit of confusion about it. Psudar 641 — 3mo

Answer this question