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

Calculating 3d deflection vector?

Asked by 8 years ago

I'm trying to create a script that shoots a beam into a mirror using raycasting. The beam is then deflected by the mirror, based on the direction the beam is coming from, where it hit the mirror, and the rotation of the mirror. However, I don't know how to piece that all together to calculate the direction the beam will be deflected in. If anyone has any ideas, algorithms, or helpful links, please let me know. Thanks.

The mirror will always be rectangular, so the algorithm doesn't have to work universally for every shape.

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

The normal of a plane is the direction pointing away from the surface (e.g., the normal along the top of a table is "up").

A direction d can be reflected through a plane defined by unit normal n with the following formula:

reflection = d - 2 * d:dot(n) * n

You can get the normal of the surface that a ray collides with using FindPartOnRay.

0
Thanks, I'm assuming this works on all shapes then? aquathorn321 858 — 8y
1
It works on all shapes, but it's based on their physical shape. E.g., Cylinders will act like spheres, and meshes are ignored. BlueTaslem 18071 — 8y
Ad

Answer this question