Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Raycasting: Direction Value? [closed]

Asked by
SanityMan 239 Moderation Voter
10 years ago

I have been looking at some wiki pages on Raycasting, and I have failed to understand how to direct the ray where you want it. I know that to make a ray, you do something like this:

local ray = Ray.new(startposition, direction?)

The thing I don't understand is what to put to make the ray go in the way I want. Do I have to put another point along the path I want it to go on?

Also, I am wondering if/how it is possible to send a ray in a certain direction based on a mouse click on the screen.

Thanks in advance!

Locked by SanityMan, Perci1, Shawnyg, and BlueTaslem

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
1
Answered by
2eggnog 981 Moderation Voter
10 years ago

The direction is equal to (endpoint-startpoint).unit * length. Subtracting the starting point from the ending point results in a vector pointing in the correct direction, and .unit normalizes that vector so that all components are less than or equal to one. To create a ray from any point to the mouse's target, simply set the endpoint in that formula to Mouse.Hit.p.

2
You'll also have to remember that if you don't change the length of the direction unit, and you keep it as a unit, the Ray will only detect things 1 stud away from the origin TurboFusion 1821 — 10y
0
To elaborate on TurboFusion's answer: While not documented, "direction" really is the direction and DISTANCE that a raycast will look in. A length 10 vector will go 10 studs, etc, so usually very large, like 1000, vectors are necessary to make it useful. BlueTaslem 18071 — 10y
Ad