Game Development Community

How do I mount to an object's link point in script?

by Conor O Kane · in Torque Game Builder · 04/01/2007 (4:40 am) · 10 replies

Mounting an object to another object's link point is easy in the editor, but how do I do this in script? The mount function doesn't seem to have any link options - and getLinkPoint just returns the location of a link point, not the link itself.

I want to be able to spawn objects and have them mount to my player's link points with a mount force.

#1
04/01/2007 (12:02 pm)
Set the "mountedTo" to the value of the objects "mountId" you want to mount it too ...

#  getLinkCount()
#  getLinkPoint(%id)

If your player has 5 link points on it, you can call getLinkPoint(3) to get the information about the 3rd Link Point ... you would then pass this information into the spawned objects mount() function
#2
04/03/2007 (5:28 am)
That doesn't seem to be working for me. I'm using this function to mount a 'drone' to my player's ship:

function miniDrone::attachToPlayer(%this, %linkTarget)
{
  %this.mount($pDrone.getLinkPoint(%linkTarget), 0, 0, $pDrone.miniDroneForce, false, true, true, true);
  .
  .
  .

and I'm passing in link point numbers, but the mounted objects are just sitting in the middle of the world, not mounted.

If I use this code:

function miniDrone::attachToPlayer(%this, %xOffset, %yOffset)
{
  %this.mount($pDrone, %xOffset, %yOffset, $pDrone.miniDroneForce, false, true, true, true);
  .
  .
  .

Then the objects mount correctly - but I have to pass in offset values rather than reading them from the linkpoints I've placed in the editor - it's a workaround, but it's messy and will get more complicated as I start adding more linkpoints.
#3
04/03/2007 (6:46 am)
Hi.
I'm not sure, but I think that the .getLinkPoint should be passed as the secon/third parameter, like this:

function miniDrone::attachToPlayer(%this, %linkTarget)
{
  %this.mount($pDrone, $pDrone.getLinkPoint(%linkTarget), $pDrone.miniDroneForce, false, true, true, true);
  .  .  .

Hope this helps you.

Bye,
Jacopo
#4
04/03/2007 (7:08 am)
Ah I see, so the 2nd and 3rd paramaters in the mount command can be combined into a variable that contains both x and y values?

Well that makes sense, but when I try it, the mounted objects don't appear at all.
#5
04/03/2007 (7:21 am)
Any error on the console log?
#6
04/03/2007 (10:35 am)
Ok, I just made some tests and found the problem.
GetLinkPoint returns the position of the link point in World coordinates, but the mount method expects the offset in local coords.
You are mounting the object, but can't see it becouse its outside the screen.

If you transform the coords in local space all should work correctly.
Try this:

function miniDrone::attachToPlayer(%this, %linkTarget)
{
  %this.mount($pDrone, $pDrone.getLocalPoint($pDrone.getLinkPoint(%linkTarget)), $pDrone.miniDroneForce, false, true, true, true);
  .  .  .

Don't know if there is a better way to get the local coords directly from the object.

Bye,
Jacopo
#7
04/08/2007 (5:43 am)
That worked a treat! Thanks for your help.
#8
04/08/2007 (6:39 am)
And for my next trick - I want to mount something offset slightly from a link point.

How do I edit one part of a vector variable. When I call

%location = %something.getLocalPoint(%something.getLinkPoint(1))

I get a vector value in %location, like (0.1 0.5). How do I add to only the X component of that vector, so that I can pass (0.1+%offset 0.5)?

[edit] - never mind, I found the t2dVectorAdd function. I am a n00b.
#9
04/08/2007 (12:18 pm)
Conor, you can also use getWord and setWord to change values in a vector/list ...
#10
04/08/2007 (9:14 pm)
Thanks David - that sounds like a simpler solution, since I only want to modify the X component of the location.