Game Development Community

Mount questions

by Pablo Alonso · in Torque Game Builder · 03/02/2005 (5:21 pm) · 9 replies

When I mount an fxStaticSprite2D 'A' on another 'B' and set the mountForce to 0 so they move toghether, but when I move B with setLinearVelocityX, A starts to get a little behind, it's just a couple of pixels, but it does sepparate from A, maybe it's because I keep changing setLinearVelocityX because I want to acomplish an accelerated movement. So anyways, my question is if there's any way I can them to move toghether with mount? because right now I discarded the mount function and am using setLinearVelocityX on both objects, so they move side by side.

Another mount questions, when I mount an object how can I rotate it?

And last question... but not a mount question... is there any way to move the pivot point of a fxStaticSprite2D? or does it always rotates from the center of the image?

Thanks a lot

#1
03/02/2005 (5:31 pm)
From the refrance docs for Mount()
Quote:
fxSceneObject2D - The object to be mounted to. Any object can be mounted, including
chains of objects but circular loops of mounts are not allowed e.g. you try to mount an object
which itself is mounted to something else which in turn, somewhere is mounted back to this
object.
offsetX/Y Defines the mount-point which is this offset from the target objects pivot-point.
mountForce - The force constantly applied to the object allowing it to 'chase' the specified
mount point. This allows you to have a non-rigid mount on the object which, if it moves, this
object will 'chase' the mount point using this force. A force of 0 indicates that the mount is
rigid and will track the mount-point perfectly every frame (this is the default).
trackRotation? Specifies that when mounted, should this object track the target objects
rotation e.g. rotate with it. The object will constantly track its mount-point which will mean that
it may rotate around the object (if it had a large offset from the target object) but rotation here
means that the object also rotates around its own pivot-point. The default is true.
sendToMount? Indicates whether the object should be sent directly to the specified mount
point immediately. If this is not specified then the object will immediately start moving towards
the mount-point. If the mountForce is 0 then the object will move to the mount-point on the
next frame anyway, regardless of this setting. The default is true.
ownedByMount? Indicates whether the object is to be owned by the object its mounting to.
What this means is that when the object that we're mounting to, is deleted, this object is
automatically deleted. This is extremely useful for objects that are mounted that you don't
want to explicitly track. The default is true.
inheritAttributes? Indicates whether the object inherits attributes from the object being
mounted to. At the moment, the following atributes are inherited:-
- Enabled, Visible and Flip.
When the object is dismounted, these attributes are not restored to their previous settings
before the object was mounted, the changes are permanent. The default is true.
NOTE:- Using an offset of (0,0); both objects will be aligned using their pivot-points. For
instance, if one object has the pivot-point at top/left and the other center/center then the fully
mounted objects will overlap with the top/left and center/center of the objects at the same
position. You can mount as many objects to another object as you require, there are no limits
apart from a small computational increase.
This function returns the "link-index" which can be used by "getLinkPoint()" to retrieve the
current position of the mount-point. Note that the mount is placed onto the object that's being
mounted-to and not the object that's mounting. The function will return "-1" if the mount is
invalid for any reason.
#2
03/02/2005 (5:36 pm)
Yeah, my problem is that even when I set the mountForce to 0 they don't move exactly the same, they have a couple pixels of difference.

About the rotation imagine an arm and a torso, you want the arm to rotate when the torso rotates but it also should rotate by itself, that's what I don't know how to acomplish, how can I rotate just the arm, setRotation doesn't work after mount is used.

Thanks
#3
03/02/2005 (9:11 pm)
Pablo is correct. I think this is a bug. I mounted an object with 0 mountForce and there is a noticeable lag.

Also, I set sendToMount to false (on an object with mountForce of 20), but the object appeared at the mount instantly, so this might also be a bug.
#4
03/03/2005 (12:38 am)
@Pablo: With a mount-force of zero (special case of rigid-mount), no matter what you do to the parent, the object should stay mounted at the exact position. I'll check this myself to confirm and let you know if there is in-fact a bug.

Setting trackRotation? to false allows you to still control the rotation yourself as usual. The default is true though so the object tracks the parents rotation so it looks rigidly mounted.

Quick Search reveals: Pivot-Points. :)


@Jason: I'll check that but it has been used several times in the demos so I'm very suprised by this. If so, I'll let you know.

Thanks for the heads-up guys.

- Melv.
#5
03/03/2005 (3:00 am)
Here's an example just replace the end of client/client.cs with:

// ************************************************************************
    //
    // Add your custom code here...
    //
    // ************************************************************************
    createPlayer();
    createCompanion();
}

function createPlayer ()
{
    datablock fxImageMapDatablock2D(playershipImageMap)
    {
        mode = full;
        textureName = "~/client/images/brick";
    };
    $player = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
    $player.setPosition("-50 25");
    $player.setSize( "10 10" );
    $player.setImageMap( playershipImageMap );
    schedule(2000, 0, "playerAccelerateRight");
}

function playerAccelerateRight()
{
    %xVel = $player.getLinearVelocityX();
    if(%xVel < 30)
    {
        schedule(30, 0, "playerAccelerateRight");
        %xVel ++;
        $player.setLinearVelocityX( %xVel );
    }
}

function createCompanion ()
{
    datablock fxImageMapDatablock2D(cannonImageMap)
    {
        mode = full;
        textureName = "~/client/images/brick";
    };
    $companion = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
    $companion.setSize( "10 10" );
    $companion.setImageMap( cannonImageMap );
    $companion.setAutoRotation(10);
    $companion.mount($player, "0 -2", 0);
}

I use the brick image and you can see clearly a 2 or so pixel difference between the two

thanks
#6
03/03/2005 (11:26 am)
@Robert: Maybe you already saw this thread about that very subject? :)

@Melv: I'm probably doing something wrong to cause the object to appear instantly at the mount point. But I do know that the rigid mounting seems to be not so rigid.
#7
03/30/2005 (9:10 am)
FYI

I have fixed this problem. It will be included in the next update.

Thanks for the report.

- Melv.
#8
03/30/2005 (10:10 am)
Aha so I wasnt' just seeing things :)
#9
03/30/2005 (10:19 am)
Nope. :)

- Melv.