Moving objects by a link point?
by Nick Sabalausky · in Torque Game Builder · 03/22/2005 (6:37 pm) · 5 replies
I know I can get by without it, but it would be nice if it were possible to do something like this:
// Contrived example
$thing.leftEdge = $thing.addLinkPoint("-1 0");
$thing.leftEdge.setPosition("4 7"); // Move $thing so that it's left edge is at (4,7)
Is there a built-in way to do this, or do I have to explicitly subtract the coordinates to get the vector between the points and then offset my "$thing.setPosition()" by that vector?
// Contrived example
$thing.leftEdge = $thing.addLinkPoint("-1 0");
$thing.leftEdge.setPosition("4 7"); // Move $thing so that it's left edge is at (4,7)
Is there a built-in way to do this, or do I have to explicitly subtract the coordinates to get the vector between the points and then offset my "$thing.setPosition()" by that vector?
About the author
#3
then just simply call this function passing the object and the link point
03/23/2005 (7:35 am)
You could make a function to Quote:Is there a built-in way to do this, or do I have to explicitly subtract the coordinates to get the vector between the points and then offset my "$thing.setPosition()" by that vector?
then just simply call this function passing the object and the link point
#4
03/23/2005 (8:25 am)
Quote:You could make a function to ... then just simply call this function passing the object and the link pointWell, I just wasn't sure if there was already a built-in way to do it. But yea, I've just now gone ahead and written a function for it. The code is a lot simpler than I originally thought it would be (The Torque scripting language is awesome :) ). Here it is for anyone who's interested:
function fxSceneObject2D::setPositionByLinkPoint(%this, %linkPoint, %position)
{
%offsetVector = vectorSub(%this.getLinkPoint(%linkpoint), %this.getPosition());
%this.setPosition(vectorSub(%position, %offsetVector));
}
// Sample usage:
$thing.myLinkPoint = $thing.addLinkPoint("-1 -1");
$thing.setPositionByLinkPoint($thing.myLinkPoint, "17 15");
#5
03/23/2005 (8:33 am)
Very cool :)
Employee Melv May
The "addLinkPoint()" does not return an object, it returns a position like "100 200" so you can't call functions from it. That's like doing...
"100 200".setPosition("300 400");... which makes no sense really.A later update will allow you to set the pivot-point (point of position/rotation) so you can position your object from arbitrary points on your object if that helps.
- Melv.