Game Development Community

Beginner question about TGB - mounting a t2dSceneObject to a...

by Josias Gibbs · in Torque Game Engine · 08/15/2008 (1:07 pm) · 5 replies

I'm trying to mount a t2dSceneObject to a Static Sprite (the player's ship) so that when the static sprite moves around, the t2dSceneObject moves with it, but doesn't rotate with it (ie: if the static sprite rotates, the t2dSceneObject does nothing, but if the static sprite moves to the upper right, the t2dSceneObject moves to the upper right)

I'm assuming that there's an extremely easy way to do this, so... what is it?

#1
08/15/2008 (1:31 pm)
Do you want to mount them in the editor or in script? If in script you would use one of the methods listed here.
tdn.garagegames.com/wiki/TGB/Reference:_t2dSceneObject_Mounting_Methods

Notice the trackRotation parameter.
#2
08/17/2008 (10:18 am)
Ok - I wrote out a behavior based on the CameraMount behavior from this site, and applied it to the player's ship - but it doesn't seem to have any effect. Is there an obvious syntax error I'm not seeing?

if (!isObject(MountToThisBehavior))
{
%template = new BehaviorTemplate(MountToThisBehavior);

%template.friendlyName = "Mount an Object to This";
%template.behaviorType = "Effects";
%template.description = "Mounts an object to the current object.";

%template.addBehaviorField(object, "The object to mount to the current object.", object, "", t2dSceneObject);
%template.addBehaviorField(xMount, "X location in target to mount to.", float, 0);
%template.addBehaviorField(yMount, "Y location in target to mount to.", float, 0);
%template.addBehaviorField(mountForce, "Strength of mounting. 0 = rigid", float, 0);
}

function MountToThisBehavior::onAddToScene(%this, %scenegraph)
{

%this.schedule(1000, "scheduledMount");

}

function MountToThisBehavior::scheduledMount(%this)
{
object.mount(%this.owner, %this.xMount, %this.yMount, %this.mountForce, true);
}
#3
08/17/2008 (12:51 pm)
Object.mount(...) ,should be, %this.object.mount(...)
#4
08/18/2008 (12:23 am)
I changed the last line to this:

%this.object.mount(%this.owner, %this.xMount, %this.yMount, %this.mountForce, true);



but... it still doesn't seem to do anything. I'm trying to mount the object specified in the line:
%template.addBehaviorField(object, "The object to mount to the current object.", object, "", t2dSceneObject);
to myself (ie: %this). I'm an experienced c++ programmer, but I'm very very new to TGB. If anyone can help me figure out what's wrong with this, I'd appreciate it.

Wow, I'm really tired - I'll check back tomorrow morning.
#5
08/20/2008 (12:12 pm)
Ahh - I figured out my problem. Your change actually did fix it.