Game Development Community

MyObject.addLinkPoint does not work right from console?

by Dave Calabrese · in Torque Game Builder · 08/03/2006 (12:21 pm) · 5 replies

What I am trying to do is programatically place link nodes on an object so I can have an even grid of link points. To do this, I have created a scene object. I then dropped the console and typed:

myNewObject.addLinkPoint(50,50);

Watching the link nodes on the object... nothing happened.

If I now try and add a new link point through the 'Add Link Point' point/click editor, it adds a new link point that has a value of one higher than before (meaning that the addLinkPoint function made it at least think a new point exists).

When I select another object and select "Mount this object to another object", the only link points that I see on the 'myNewObject' object are the ones that I placed through the point/click editor.

So... what's going on there? Is this a bug, or is there a trick I'm missing to adding link points through T2D Scripting?

Thanks,
-Dave C.

#1
08/03/2006 (12:27 pm)
When you use 'addLinkPoint', the parameters should be in object space (ie from -1 to +1). Therefore, by putting 50, you won't get the results you want. To convert from "50, 50", which I assume is your world space, use "getLocalPoint". This will convert it to the sprite's object space. Hopefully that should fix it :)
#2
08/03/2006 (12:33 pm)
Well, that sorta worked... I tried the following:

myNewworld.addLinkPoint(myNewWorld.getLocalPoint(5,10));

And no matter where I moved the object, tie placed it at '5,10' in the actual world, and not in my object.
#3
08/03/2006 (12:44 pm)
Try something like this:
$localPos = $myNewWorld.getLocalPoint(5, 10); 
 myNewObject.addLinkPoint(getWord($localPos, 0), getWord($localPos, 1));

edit: forgot to explain what the code does.
$localPos is a variable which will store the converted position. 'getLocalPoint' returns a vector, so you will recieve an X value and a Y value. You use getWord($localPos, 0) to get the first value (which is X) and then ($localPos, 1) to get the second value (which is Y). You use these values as the parameters and hopefully that should work :)
#4
08/03/2006 (1:04 pm)
Ok, now that does work! But... I'm still kinda confused.

When I use 'getLocalPoints(0,0), and then do the above, it places the link point around the bottom center of the object instead of the very center of the object.
#5
08/03/2006 (1:06 pm)
Don't forget, when you use "getLocalPoint", the "0,0" you enter is in world co-ordinates, not object-space co-ordinates. That's why it's not in the centre of the object. "0,0" object space would be the centre of the object. For more info on World Space and Object Space, check the TGB reference.