Game Development Community

T3D 1.1 SpawnSphere usability improvement

by Daniel Buckmaster · in Torque 3D Professional · 01/24/2012 (1:16 pm) · 0 replies

Platform: Windows 7 32 bit
Build: Torque 3D 1.1 Final
Target: SpawnSphere class

SpawnSphere, when used to spawn AIPlayer objects without the aid of a spawn script like the one used to spawn Players in the standard templates, dumps its spawnees at an indeterminate location, which seems to be centred on the origin horizontally, but some distance in the air.

Anyway. I made some modifications; here's a patch that will add a flag that causes SpawnSpheres to set their spawnees' transform after creation:
Index: D:/GG/warengine3d/Engine/source/T3D/missionMarker.h
===================================================================
--- D:/GG/warengine3d/Engine/source/T3D/missionMarker.h	(revision 112)
+++ D:/GG/warengine3d/Engine/source/T3D/missionMarker.h	(revision 113)
@@ -159,6 +159,7 @@
       String   mSpawnProperties;
       String   mSpawnScript;
       bool     mAutoSpawn;
+      bool     mOrientObject;
 
       // Radius/weight info
       F32      mRadius;
Index: D:/GG/warengine3d/Engine/source/T3D/missionMarker.cpp
===================================================================
--- D:/GG/warengine3d/Engine/source/T3D/missionMarker.cpp	(revision 112)
+++ D:/GG/warengine3d/Engine/source/T3D/missionMarker.cpp	(revision 113)
@@ -360,6 +360,7 @@
 SpawnSphere::SpawnSphere()
 {
    mAutoSpawn = false;
+   mOrientObject = true;
 
    mRadius = 100.f;
    mSphereWeight = 100.f;
@@ -397,6 +398,13 @@
    // If we have a spawnObject add it to the MissionCleanup group
    if (spawnObject)
    {
+      if(mOrientObject)
+      {
+         SceneObject* sceneObject = dynamic_cast<SceneObject*>(spawnObject);
+         if(sceneObject)
+            sceneObject->setTransform(getTransform());
+      }
+
       SimObject* cleanup = Sim::findObject("MissionCleanup");
 
       if (cleanup)
@@ -424,6 +432,7 @@
    if(stream->writeFlag(mask & UpdateSphereMask))
    {
       stream->writeFlag(mAutoSpawn);
+      stream->writeFlag(mOrientObject);
 
       stream->write(mSpawnClass);
       stream->write(mSpawnDataBlock);
@@ -445,6 +454,7 @@
    if(stream->readFlag())
    {
       mAutoSpawn = stream->readFlag();
+      mOrientObject = stream->readFlag();
 
       stream->read(&mSpawnClass);
       stream->read(&mSpawnDataBlock);
@@ -487,6 +497,7 @@
    addField("spawnProperties",   TypeRealString,      Offset(mSpawnProperties, SpawnSphere), "String containing ; delimited properties that are set at the time of spawning");
    addField("spawnScript",       TypeCommand,         Offset(mSpawnScript,     SpawnSphere), "Command to execute when spawning an object. New object id is stored in $SpawnObject.  Max 255 characters." );
    addField("autoSpawn",         TypeBool,            Offset(mAutoSpawn,       SpawnSphere), "Flag to spawn object as soon as SpawnSphere is created, true to enable or false to disabled");
+   addField("orientObject",      TypeBool,            Offset(mOrientObject,    SpawnSphere), "Flag to set the object to the same position as the SpawnSphere on creation.");
    endGroup("Spawn");
 
    addGroup("Dimensions");

About the author

Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!