CloneWithbehaviours and mounts
by Saiko · in Torque Game Builder · 04/25/2007 (9:02 am) · 1 replies
Hey there,
I've just been playing around with the idea of using behaviours to spawn objects with mounts. After about 10 mins playing with TGB 1.5b3 it looks like it doesn't work. My question is should it? When spawned the only a clone of the original object appears with no mount. The mount stays in the position it started. If the mount is set to template as well its hidden too but remains where the original object was.
The reason I ask is you can make some really interesting objects with a mount stack. The simplest example I can think of is a player tracking cannon mounted on an asteroid that gets spawned at a set time. The cannon would track the player independently of the asteroid movement. Not a particularly interesting object by itself but it has potential. It works a treat until you try to spawn them. This could easily be done with script but would be great if it could be done completely with behaviours.
Playing around with this reminded me about the visibility checks I added to the shoot behaviours. (The hidden mount from the original object template shoots with standard Timed Shoot!) If anyone wants the tweaks I'll post them as there is nothing more annoying than being shot by something invisible :)
I've just been playing around with the idea of using behaviours to spawn objects with mounts. After about 10 mins playing with TGB 1.5b3 it looks like it doesn't work. My question is should it? When spawned the only a clone of the original object appears with no mount. The mount stays in the position it started. If the mount is set to template as well its hidden too but remains where the original object was.
The reason I ask is you can make some really interesting objects with a mount stack. The simplest example I can think of is a player tracking cannon mounted on an asteroid that gets spawned at a set time. The cannon would track the player independently of the asteroid movement. Not a particularly interesting object by itself but it has potential. It works a treat until you try to spawn them. This could easily be done with script but would be great if it could be done completely with behaviours.
Playing around with this reminded me about the visibility checks I added to the shoot behaviours. (The hidden mount from the original object template shoots with standard Timed Shoot!) If anyone wants the tweaks I'll post them as there is nothing more annoying than being shot by something invisible :)
Torque Owner Saiko
If anyone thinks its useful I'll give it a consistent type and name and add it to the other behaviours. (I use the housekeeping type generally for my behaviours like limitedLifeTime which help clean up projectiles that lurk forever).
if (!isObject(Mountie)) { %template = new BehaviorTemplate(Mountie); %template.friendlyName = "Mountie"; %template.behaviorType = "Housekeeping"; %template.description = "Mounts a template object to another template object."; %template.addBehaviorField(object, "The template object to mount to this object.", object, "", t2dSceneObject); %template.addBehaviorField(offsetX, "The x position to mount to in the object space of this object.", float, "0"); %template.addBehaviorField(offsetY, "The y position to mount to in the object space of this object.", float, "0"); %template.addBehaviorField(force, "The magnitude of the force constantly applied to the object to keep it at the mount point. A value of 0 makes the mount rigid, and thus stuck to the object it is mounted to.", float, "0"); %template.addBehaviorField(trackRotation, "Whether or not to track the rotation of the object this is being mounted to.", bool, false); %template.addBehaviorField(sendToMount, "Whether or not to send the object directly to the mount point.", bool, false); %template.addBehaviorField(ownedByMount, "Whether or not the object is deleted when the object it is mounted to is deleted.", bool, false); %template.addBehaviorField(inheritAttributes, "Whether or not to inherit certain attributes from the object this is being mounted to. The inherited attributes are enabled, visible, paused, and flip.", bool, false); } function Mountie::onAddToScene(%this) { if (!isObject(%this.object)) return; %newObject = %this.object.cloneWithBehaviors(); %newObject.mount(%this.owner, %this.offsetX, %this.offsetY, %this.force, %this.trackRotation, %this.sendToMount, %this.ownedByMount, %this.inheritAttributes); }