Ad
Log in to vote
0

What's the third value that FindPartOnRay returns?

Asked by
SurVur 86
7 years ago

It says on the wiki the "surface normal". Can someone further explain?

0
Basically the side of the part which was hit DigitalVeer 1473 — 7y
0
A surface normal is a vector (mathematical entity) that points perpendicularly to the plane of the surface. See this diagram for an illustration: http://bit.ly/1GbLQPV duckwit 1404 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

You can experiment for yourself. Open a new place and add two bricks; name one of them Origin. Now put the following code into the Command Bar:

ray = Ray.new(workspace.Origin.Position, (workspace.Part.Position - workspace.Origin.Position).unit*999) print(workspace:FindPartOnRay(ray))

It should print something like

Part -0.357828766, 0.99999994, -0.302775055 0, 1, 0

If the first word is "nil", the bricks are too far apart. The next 3 numbers tell you the position of where the ray hit the part. The last 3 numbers are the "surface normal" -- that will be a unit vector perpendicular to the surface that you hit. For instance, if the ray hits the part on the top of the part (assume the part is not rotated at all), the "normal" to the top of the part is straight up (straight down would technically work too, but I assume the surface normal will always point away from the centre of the part).

Say you got the output above and then you flipped the part so that the bottom of the part is facing upwards. The output (and surface normal) won't change: though the ray is now hitting the "bottom" of the part, the bottom surface is currently "facing upwards", so the surface normal is still (0, 1, 0).

Ad

Answer this question