Snap to Path
by Larry Jennings II · in General Discussion · 04/06/2011 (6:54 am) · 1 replies
I have a scene object i am attaching to a path through the code. I would like to know if their are any shortcut methods on how to snap that node to the path, based on where its at.
I know you can reset to the start but i dont want that, i want it to snap to the nearest point on the path.
Any Ideas? or am i just gonna have to do it the hard way and test the signed distances and whatnot?
Edit: Also, how do you get a path node's position? I'm not seeing anything on the reference page.
I know you can reset to the start but i dont want that, i want it to snap to the nearest point on the path.
Any Ideas? or am i just gonna have to do it the hard way and test the signed distances and whatnot?
Edit: Also, how do you get a path node's position? I'm not seeing anything on the reference page.
About the author
College student interested in serious game dev.
Torque 3D Owner Kage
%path = "MissionGroup/Paths/Path1"; if ( isObject( %path ) ) { %myobjpos = %myobj.getPosition(); /* <-- assume your object name is myobj */ %closestnode = %path.getObject( 0 ); %closestdist = VectorDist( %myobjpos, %closestnode.getPosition() ); /* iterate thru all nodes in the path to find the closest one */ for (i = 1; i < %path.getCount(); ++i ) { %node = %path.getObject( i ); %dist = VectorDist( %node.getPosition(), %myobjpos ); if ( %dist < %closestdist ) { %closestnode = %node; %closestdist = %dist; } } /* closest node found - at this point, you can query the node for its transformation or position; if you don't care about its rotation then just get the position */ %myobj.setTranform( %closestnode.getTransform() ); } else echo( "no path found" );gl.