Game Development Community

Mounting

by Jeremy Tilton · in Torque Game Builder · 03/12/2005 (8:20 am) · 6 replies

I'm trying to mount a few pieces together. I am putting user inputs on what I'm calling "Piece". Anything else that is mounted should move with it in a very rigid way to include rotation. Both "Pieces" are just static sprites, nothing special. I have set up the link point like this:

$piece.LeftLinkPoint = $piece.addLinkPoint("-1 0");

and I have mounted piece2 like this:

$piece2.mount($piece, $piece.getLinkPoint($piece.LeftLinkPoint), 0, true, true, false, true);

"Piece2" does rotate around "piece" in a very rigid fashion that I am looking for, and moves with it in a desired way, it is just way far away. It is only supposed to be 1 world unit away and it is nearly off the screen. But the world space is nearly 60 units across. I tried changing the number to 0.1 instead of 1 and it is in the same exact spot.

I'm thinking maybe it has something to do with the scaling I performed on the images? So for more info on that if you need it: Each "Piece" is currently using the same image, nothing more than a 32X32 box. I set their size to 4X4 when I initially set up the images:

$piece.setSize("4 4");

So does scaling do something to mounting?

#1
03/13/2005 (2:27 am)
Yes, the mounting system uses the same coordinate-system as the collision-polygon one.

(0,0) is the center of your object, (-1,-1) is the top-left, (1,1) is the bottom-right and so on.

The reason for this is so that the position you mount to on an object is independant of size. If you size the object, you want the mount-point to be the same (just like you would the collision-polygon).

If you mount to "-1 0" in your example, you're asking to mount to the far left/middle of the object which you want to be no matter what size it is.

Do this make sense?

- Melv.
#2
03/13/2005 (8:00 am)
I realized that last night while playing around and after giving up on this implementation. I chose -1 0, to find out where it would mount, but I as actually aiming for the left center of the object. I was trying to mount a box to another one so that they are flush next to eachother. But "-1 0" was way off the screen when my other image was in the center. So scale shouldn't matter? -1 0 will be the left middle after it is scaled down?
#3
03/13/2005 (8:55 am)
Took another stab at this, and here's what happened:

mounted pieces are still uber-far away when I specify link points:

$piece.LeftLinkPoint = $piece.addLinkPoint("-1 0");
$piece.TopLinkPoint = $piece.addLinkPoint("0 -1");
$piece.RightLinkPoint = $piece.addLinkPoint("1 0");
$piece.BottomLinkPoint = $piece.addLinkPoint("0 1");

$piece2.mount($piece, $piece.getLinkPoint($piece.RightLinkPoint), 0, true, true, false, true);

However, if I specify an actual point in the mounting function and ignore link points:

$piece2.mount($piece, "-1 0", 0, true, true, false, true);

Not only are they not far away, they are all bunched up. I have to change it to
"-2 0".

I thought maybe it was because the linkpoints are based on the original size of the tile, and since I scaled it down from 32 to 4, I'd use 0.125, but still the same result, same distance away. Should I call an exorcist?
#4
03/13/2005 (9:06 am)
Jeremy,

You're using that all wrong. "getLinkPoint()" returns either a previous mounted-point or an explicit point added using "addLinkPoint()" and it returns the current position in world-space as that's what it's used for.

Let me explain this a little:-

When you use "mount()" or "addLinkPoint()", they both return you an index which can be used by "getLinkPoint()" to return the current world-space position which can obviously change from frame-to-frame if the object in question is moving, rotating or is scaled.

The idea behind "getLinkPoint()" is to allow you to get access to the current positions of either mounted-objects or specific points of your object for things like emiting projectiles or doing effects. Typically you wouldn't use it on "mount()" points but you can as they both use the same system.

An example...

// Set Position.
$sprite1.setPosition("100 200");
$sprite1.setSize( "10 10" );

// Return link-index for center of object.
%linkIndex1 = $sprite1.addLinkPoint("0 0");
%linkIndex2 = $sprite1.addLinkPoint("1 1");

// Get Positions.
%pos1 = $sprite1.getLinkPoint(%linkIndex1);
%pos2 = $sprite1.getLinkPoint(%linkIndex2);

// Should dump "100 200".
echo( %pos1 );
// Should dump "105 205".
echo( %pos2 );

... or ...

// Set Position.
$sprite1.setPosition("100 200");

// Return link-index for center of object.
%linkIndex = $sprite2.mount( $sprite1, "0 0" );

// Get Position.
%pos = $sprite1.getLinkPoint(%linkIndex);

// Should dump "100 200".
echo( %pos );

Does that make it clearer?

- Melv.
#5
03/13/2005 (9:47 am)
I thought I got that from the tutorial, but turns out I didn't. Dunno where I got it, but thanks.
#6
03/13/2005 (9:49 am)
No problem at all.

Just ask if you have any other problems.

- Melv.