PDA

View Full Version : Shoot Ray From Vertex To Object


josiah
02-25-2007, 02:41 AM
I have three objects. I want to shoot a ray from a vertex of obj1 to a point helper, and get the intersection where the ray hits obj2.

local vertPos = getvert obj1 vertexSelection[i] -- get the position of the vertex on obj1
local rayTarget = obj3.pos -- this is the where to shoot the ray at (point helper)
local ShootRay = ray vertPos rayTarget -- shoot ray from vert to pointhelper
local TargetVect = intersectRay obj2 ShootRay -- try to get point where ray intersects obj2

Now TargetVect.pos should hold the vector where the ray hit obj2's surface.
I think rayTarget must be a direction, but how can I get a direction from the vert to the point helper that will work?

Thanks for any suggestions.

Bobo
02-25-2007, 04:17 AM
local vertPos = getvert obj1 vertexSelection[i] -- get the position of the vertex on obj1
local rayTarget = normalize (obj3.pos - vertPos) -- this is the where to shoot the ray at (point helper)
local ShootRay = ray vertPos rayTarget -- shoot ray from vert to pointhelper
local TargetVect = intersectRay obj2 ShootRay -- try to get point where ray intersects obj2
if TargetVect != undefined do format "Hit Object 2 at %\n" TargetVect.pos

josiah
02-25-2007, 11:40 PM
Thanks Bobo, that is exactly what I was looking for! I really appreciate your help.

CGTalk Moderation
02-25-2007, 11:40 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.