Turret & AITurret classes
by Paul Dana · 04/15/2003 (11:36 am) · 85 comments
Download Code File
Turrets for TGE Paul Dana
Introduction
This resource describes how to get turrets and AI-turrets into the Torque Game Engine. A Torque turret is like a real world turret: it has a weapon mounted to it and rotating the turret aims that weapon. A player can walk up to a turret and mount it and then that player is controlling the turret instead of his character. A turret can be mounted to another object, such as a vehicle. A tank could be implemented this way if the player controlled that turret. There are options for limiting the rotational freedom a turret has in pitch and yaw.
An AI-turret is a turret that can aim and fire automatically. The AI-turret class extends the Turret class and has methods for tracking and aiming at a target object or location. It can correctly "lead shots" taking into account projectile muzzle velocity and ballistic information as well as the speed of any object the turret itself is mounted to and the speed of the target object. It can aim correctly even if the turret is mounted to another object at some odd angle or, for whatever other reason, the local Z axis of the turret does not align with the world Z axis. There is a "miss radius" option for controlling how accurate the aim is.
This resources comes with a sample turret .dts file and the Milkshape .ms3d file it came from as well as one example turret datablock and two example AI turret datablocks.
I am usually very greedy with my time. I am rarely motivated to do so much work for free and write documentation for it! I made an exception in this case because I felt the Garage Game developer community deserved it. They have done so much for me. Thank you all.
How This Resource is Organized
Some resources spell out the code changes in the resource text itself. This seems a cumbersome way of doing a resource, such as this one, which will require a large number of small alterations to the code in many different files. I have taken a different approach. I have included each file that needs to be changed in a .zip file and each of the changes that need to be made are marked by the same comment. Only those sections of the file that have changed are actually included so it's easy to see where the changes are.
IMPORTANT: The files are laid out in the same folder structure used by the Torque Game Engine itself but it's important that you DO NOT unzip this file into a folder containing Torque source code. These are not complete files after all...they only show the sections that have changed. The reason for laying them out using the same folder structure is simply to make it easier to identify exactly which files have changed. Here is a sample file:
Note that all changes begin with a line reading: "// phdana turrets ->".
Note that all changes end with a line reading: "// <- phdana turrets".
How to Add Turrets to Your Code
Unzip turrets.zip to some folder on your harddrive separate from your Torque source folder. Examine the files that were unzipped. Some C++ and Script files are new (such as turret.cc and turret.h). Just copy these files as-is into the appropriate folder and make sure you add these files to the appropriate Makefile or Project file. Most of the files in the .zip file already exist (such as player.cc) and need to have changes merged into them. For each such file that was unzipped, open it up and search for "// phdana ". Now open the same file in your Torque folder, find the same section, and insert the appropriate lines of code into your source. Use the same process to merge changes to the Script files as well. Some files are new data files (such as smallTurret.dts). Just copy these files as-is to the appropriate folder.
How to Test Mounting the Turret as a Player
Once you have merged the necessary code and data files you should be able to add the test turret that comes with this resource to your mission. Run your game, enter the World Creator mode in the Mission Editor and choose to place a Shape. You should see a "Turrets" section. Place a GenericTurret somewhere on the ground in your mission.
To test the turret, enter the game as a Player and walk up to the turret. Once you touch it you should "mount" it and now your mouse motions control the turret, and the player is mounted, sitting, on the turret. You can hit TAB to enter 3rd person view to get a better look. To dismount from the turret hit the SPACEBAR or whatever key you have bound to the "jump" command.
How to Test an AI Turret
Once you have merged the necessary code and data files you should be able to add the test AI-turret that comes with this resource to your mission. Run your game, enter the World Creator mode in the Mission Editor and choose to place a Shape. You should see a "Turrets" section. Place a GenericAITurret somewhere on the ground in your mission.
To test the AI-turret, enter the game as a Player or as a Vechicle. Once you come within the "triggerRadius" of the AI Turret it should activate and then start aiming at you and eventually fire at you. If you die, since it cannot find any more targets, it should deactivate and return to zero pitch and yaw.
How to Mount a Turret on a Vehicle
It is possible to mount a turret on a vehicle. In the vehicles "onAdd()" script function you would create a new turret object and mount it to the vehicle. If you do that then the first person to touch the vehicle will mount the driver's seat and the second person to touch the vehicle will mount the turret.
It is also possible to mount a turret on a vehicle and have only one person control both the vehicle and the turret. You would do this by modifying a vehicle class (or creating your own) who's movement is controlled by the keyboard. You would expose a method to script so the script can tell the vehicle what turret is mounted to it. You would mount a turret to the vehicle using the same method as above. In this vehicle class's updateMove() method you would pass the move's pitch and yaw to the turret you mounted. Use the method outlined above to mount the turret, and in the vehicles ::onAdd() script method you would call the method you exposed to tell the vehicle about the mounted turret.
It is also possible to mount an AI-turret on a vehicle and let that turret pick it's own targets. There is nothing special you need to do in this case. Note that an AI-turret can correctly aim itself no matter what it's orientation in the world. This means a turret will aim correctly even when mounted on a wheeled vehicle climbing a hill, or on a flying vehicle in a banking curve. Mount the turret using the method outlined above but create an AITurret and set the datablock appropriately.
How to Build a Turret
The turrets presented in this resource are equivalent to the Turrets that were found in Tribes 2 in that they are mountable and can be mounted, etc. However they are built a little differently. In Tribes 2 turrets the artist had to provide two blend animation sequences called Turn and Elevate that were used by the turret code to actually aim the turret. In the turrets presented here those two animation sequences are not needed, and the artist simply has to indicate which nodes are to be used for rotating the turret by giving them the special names: codeTurret and codeWeapon. This will be explained in more detail below.
There are three advantages to this method and only one real drawback. One advantage is a simplified art-path. The artist merely has to construct the turret in a turret-like way and then indicate which nodes are to be used for rotation. The second advantage is that it requires two less threads at runtime. The third advantage, and the one most important to me, is that Turrets designed in this fashion can be constructed using Milkshape which is unable to make the blend animation sequences required by the Tribes 2 method. The drawback is that neither of these two specially named nodes can contribute to an animation. These nodes can be part of a bone system that is animated, they just cannot contribute to it. Thanks to Clark Fagot and Joe Maruschak of Brave Tree software for sharing the code that implements this method of turret rotation. This is the same method they used in their Torque based game, Think Tanks. The convention of prefixing nodes that are controlled by code with the string "code" also comes from them.
Turret requirements:
A turret must have a node (called a 'joint' in Milkshape) called codeTurret. The turret code will rotate this node about it's Z axis to control the turret's yaw. The artist should attach everything to this node that only rotates about the Z axis. This would typically be some sort of support structure that would come up from the turret base and support the rest of the turret.
A turret must have a node called codeWeapon. The turret code will rotate this node about it's X axis to control the turret's pitch. The artist should attach everything to this node that rotates up and down about the X axis to aim the gun. The codeWeapon node must be attached to the codeTurret node.
A turret must have a node called mount0. The turret code will mount the "barrel" of the turret to this mount point. A barrel is just a weapon (ShapeBaseImage) that has been mounted to a turret and is no different in any other way from any other weapon in Torque.
A turret can optionally have a node called mount1 if you want a person to be able to walk up to the turret and mount it.
A turret can optionally have an animation sequence called Activate. The turret code will play this animation forwards when activating the turret, and will play it backwards when deactivating the turret. The speed this animation sequence plays back at is controlled by parameters in the datablock for a turret.
Known Problems and Issues
1. When mounting the test turret as player, in first person view the turret's barrel disappears for certain pitch angles. I am not sure what causes this. The turret still functions...you just can't see the barrel at those angles in first person view.
2. The net code is not optimized. More bits are sent down the wire than is really necessary to control the turret.
3. I need to add sounds that will automatically be played when the turret is Activated and Decativated.
4. The net code does not currently do any client side "warping". If the server and client should ever disagree on the turret rotation values then the turret motion will be "choppy". This does not currently present a problem because there are no server side forces that affect the turret's rotation that do not also exist on the client.
5. For some odd reason two sets of datablock information shows up for the turret in the mission editor. If you click on a turret in Inspector mode and expand it's datablock fields you will see two Transform sections and two Misc sections. The duplicate sections always show the same information and their presence does not seem to affect the correct operation of the turret.
Summary
I've suffered for my art....now it's your turn.
I never really wanted to write a full-featured turret class for Torque. I started because I agreed to help Anthony Rosenbaum with a project he was working on. He had turrets in his game, he said, but they did not rotate and could I help? Sounded simple enough. He wanted turrets so he could mount them to a vehicle to make a tank. Robert Brower mentioned that he needed turrets mounted to vehicles, but AI turrets that could aim. Once word got out that I was "working on turrets" it was like a feeding frenzy.
While this was going on I decided on what commercial game Crimson Games would be working on next. As it turned out this game could take advantage of AI Turrets simply placed on the ground. I figured heck...since I need some form of turrets I might as well go ahead and make a full featured turret class since a lot of Torque developers seemed to need one. When I made that decision I did not realize how hard it would be to complete a full featured Turret class so I stupidly agreed to make one. You now have the result of that stupidity. Use it wisely.
If you have any questions email me at paul@crimsongames.com. I also idle in the #garagegames and #crimsongames channels on the irc.maxgaming.com IRC network.
Turrets for TGE Paul Dana
Introduction
This resource describes how to get turrets and AI-turrets into the Torque Game Engine. A Torque turret is like a real world turret: it has a weapon mounted to it and rotating the turret aims that weapon. A player can walk up to a turret and mount it and then that player is controlling the turret instead of his character. A turret can be mounted to another object, such as a vehicle. A tank could be implemented this way if the player controlled that turret. There are options for limiting the rotational freedom a turret has in pitch and yaw.
An AI-turret is a turret that can aim and fire automatically. The AI-turret class extends the Turret class and has methods for tracking and aiming at a target object or location. It can correctly "lead shots" taking into account projectile muzzle velocity and ballistic information as well as the speed of any object the turret itself is mounted to and the speed of the target object. It can aim correctly even if the turret is mounted to another object at some odd angle or, for whatever other reason, the local Z axis of the turret does not align with the world Z axis. There is a "miss radius" option for controlling how accurate the aim is.
This resources comes with a sample turret .dts file and the Milkshape .ms3d file it came from as well as one example turret datablock and two example AI turret datablocks.
I am usually very greedy with my time. I am rarely motivated to do so much work for free and write documentation for it! I made an exception in this case because I felt the Garage Game developer community deserved it. They have done so much for me. Thank you all.
How This Resource is Organized
Some resources spell out the code changes in the resource text itself. This seems a cumbersome way of doing a resource, such as this one, which will require a large number of small alterations to the code in many different files. I have taken a different approach. I have included each file that needs to be changed in a .zip file and each of the changes that need to be made are marked by the same comment. Only those sections of the file that have changed are actually included so it's easy to see where the changes are.
IMPORTANT: The files are laid out in the same folder structure used by the Torque Game Engine itself but it's important that you DO NOT unzip this file into a folder containing Torque source code. These are not complete files after all...they only show the sections that have changed. The reason for laying them out using the same folder structure is simply to make it easier to identify exactly which files have changed. Here is a sample file:
void MissionAreaEditor::onRender(Point2I offset, const RectI & updateRect)
{
... etc more code.
dglClearBitmapModulation();
dglDrawBitmapStretch(mTextureHandle, rect);
// draw all the objects
Vector<SceneObject*> objects;
// phdana turrets ->
U32 mask = InteriorObjectType | PlayerObjectType | VehicleObjectType |
StaticShapeObjectType | WaterObjectType | TriggerObjectType |
TurretObjectType;
// <- phdana turrets
gServerContainer.findObjects(mask, findObjectsCallback, &objects);
... etc more code
}Note that all changes begin with a line reading: "// phdana turrets ->".
Note that all changes end with a line reading: "// <- phdana turrets".
How to Add Turrets to Your Code
Unzip turrets.zip to some folder on your harddrive separate from your Torque source folder. Examine the files that were unzipped. Some C++ and Script files are new (such as turret.cc and turret.h). Just copy these files as-is into the appropriate folder and make sure you add these files to the appropriate Makefile or Project file. Most of the files in the .zip file already exist (such as player.cc) and need to have changes merged into them. For each such file that was unzipped, open it up and search for "// phdana ". Now open the same file in your Torque folder, find the same section, and insert the appropriate lines of code into your source. Use the same process to merge changes to the Script files as well. Some files are new data files (such as smallTurret.dts). Just copy these files as-is to the appropriate folder.
How to Test Mounting the Turret as a Player
Once you have merged the necessary code and data files you should be able to add the test turret that comes with this resource to your mission. Run your game, enter the World Creator mode in the Mission Editor and choose to place a Shape. You should see a "Turrets" section. Place a GenericTurret somewhere on the ground in your mission.
To test the turret, enter the game as a Player and walk up to the turret. Once you touch it you should "mount" it and now your mouse motions control the turret, and the player is mounted, sitting, on the turret. You can hit TAB to enter 3rd person view to get a better look. To dismount from the turret hit the SPACEBAR or whatever key you have bound to the "jump" command.
How to Test an AI Turret
Once you have merged the necessary code and data files you should be able to add the test AI-turret that comes with this resource to your mission. Run your game, enter the World Creator mode in the Mission Editor and choose to place a Shape. You should see a "Turrets" section. Place a GenericAITurret somewhere on the ground in your mission.
To test the AI-turret, enter the game as a Player or as a Vechicle. Once you come within the "triggerRadius" of the AI Turret it should activate and then start aiming at you and eventually fire at you. If you die, since it cannot find any more targets, it should deactivate and return to zero pitch and yaw.
How to Mount a Turret on a Vehicle
It is possible to mount a turret on a vehicle. In the vehicles "onAdd()" script function you would create a new turret object and mount it to the vehicle. If you do that then the first person to touch the vehicle will mount the driver's seat and the second person to touch the vehicle will mount the turret.
function YourVehicleData::onAdd(%this,%obj)
{
// etc. ...
// mount turret
%turret = new Turret()
{
dataBlock = GenericTurret;
};
// mount turret at whatever mount point
%obj.mountObject(%turret,3);
}
%obj.mountedTurret = %turret;
// etc....
}
function YourVehicleData::onRemove(%this, %obj)
{
// etc...
// free mounted turret
if (isObject(%obj.mountedTurret))
{
%obj.mountedTurret.schedule(300,"delete");
MissionCleanup.Add(%obj.mountedTurret);
}
}It is also possible to mount a turret on a vehicle and have only one person control both the vehicle and the turret. You would do this by modifying a vehicle class (or creating your own) who's movement is controlled by the keyboard. You would expose a method to script so the script can tell the vehicle what turret is mounted to it. You would mount a turret to the vehicle using the same method as above. In this vehicle class's updateMove() method you would pass the move's pitch and yaw to the turret you mounted. Use the method outlined above to mount the turret, and in the vehicles ::onAdd() script method you would call the method you exposed to tell the vehicle about the mounted turret.
function YourVehicleData::onAdd(%this,%obj)
{
// etc. ...
// mount turret
%turret = new Turret()
{
dataBlock = GenericTurret;
};
// mount turret at whatever mount point
%obj.mountObject(%turret,3);
}
%obj.mountedTurret = %turret;
// call our new method so the C++ code knows about the turret
%obj.setMountedTurret(%turret);
// etc....
}It is also possible to mount an AI-turret on a vehicle and let that turret pick it's own targets. There is nothing special you need to do in this case. Note that an AI-turret can correctly aim itself no matter what it's orientation in the world. This means a turret will aim correctly even when mounted on a wheeled vehicle climbing a hill, or on a flying vehicle in a banking curve. Mount the turret using the method outlined above but create an AITurret and set the datablock appropriately.
function YourVehicleData::onAdd(%this,%obj)
{
// etc. ...
// mount AI-turret
%turret = new AITurret()
{
dataBlock = GenericAITurret;
};
// mount turret at whatever mount point
%obj.mountObject(%turret,3);
}
%obj.mountedTurret = %turret;
// etc....
}How to Build a Turret
The turrets presented in this resource are equivalent to the Turrets that were found in Tribes 2 in that they are mountable and can be mounted, etc. However they are built a little differently. In Tribes 2 turrets the artist had to provide two blend animation sequences called Turn and Elevate that were used by the turret code to actually aim the turret. In the turrets presented here those two animation sequences are not needed, and the artist simply has to indicate which nodes are to be used for rotating the turret by giving them the special names: codeTurret and codeWeapon. This will be explained in more detail below.
There are three advantages to this method and only one real drawback. One advantage is a simplified art-path. The artist merely has to construct the turret in a turret-like way and then indicate which nodes are to be used for rotation. The second advantage is that it requires two less threads at runtime. The third advantage, and the one most important to me, is that Turrets designed in this fashion can be constructed using Milkshape which is unable to make the blend animation sequences required by the Tribes 2 method. The drawback is that neither of these two specially named nodes can contribute to an animation. These nodes can be part of a bone system that is animated, they just cannot contribute to it. Thanks to Clark Fagot and Joe Maruschak of Brave Tree software for sharing the code that implements this method of turret rotation. This is the same method they used in their Torque based game, Think Tanks. The convention of prefixing nodes that are controlled by code with the string "code" also comes from them.
Turret requirements:
A turret must have a node (called a 'joint' in Milkshape) called codeTurret. The turret code will rotate this node about it's Z axis to control the turret's yaw. The artist should attach everything to this node that only rotates about the Z axis. This would typically be some sort of support structure that would come up from the turret base and support the rest of the turret.
A turret must have a node called codeWeapon. The turret code will rotate this node about it's X axis to control the turret's pitch. The artist should attach everything to this node that rotates up and down about the X axis to aim the gun. The codeWeapon node must be attached to the codeTurret node.
A turret must have a node called mount0. The turret code will mount the "barrel" of the turret to this mount point. A barrel is just a weapon (ShapeBaseImage) that has been mounted to a turret and is no different in any other way from any other weapon in Torque.
A turret can optionally have a node called mount1 if you want a person to be able to walk up to the turret and mount it.
A turret can optionally have an animation sequence called Activate. The turret code will play this animation forwards when activating the turret, and will play it backwards when deactivating the turret. The speed this animation sequence plays back at is controlled by parameters in the datablock for a turret.
Known Problems and Issues
1. When mounting the test turret as player, in first person view the turret's barrel disappears for certain pitch angles. I am not sure what causes this. The turret still functions...you just can't see the barrel at those angles in first person view.
2. The net code is not optimized. More bits are sent down the wire than is really necessary to control the turret.
3. I need to add sounds that will automatically be played when the turret is Activated and Decativated.
4. The net code does not currently do any client side "warping". If the server and client should ever disagree on the turret rotation values then the turret motion will be "choppy". This does not currently present a problem because there are no server side forces that affect the turret's rotation that do not also exist on the client.
5. For some odd reason two sets of datablock information shows up for the turret in the mission editor. If you click on a turret in Inspector mode and expand it's datablock fields you will see two Transform sections and two Misc sections. The duplicate sections always show the same information and their presence does not seem to affect the correct operation of the turret.
Summary
I've suffered for my art....now it's your turn.
I never really wanted to write a full-featured turret class for Torque. I started because I agreed to help Anthony Rosenbaum with a project he was working on. He had turrets in his game, he said, but they did not rotate and could I help? Sounded simple enough. He wanted turrets so he could mount them to a vehicle to make a tank. Robert Brower mentioned that he needed turrets mounted to vehicles, but AI turrets that could aim. Once word got out that I was "working on turrets" it was like a feeding frenzy.
While this was going on I decided on what commercial game Crimson Games would be working on next. As it turned out this game could take advantage of AI Turrets simply placed on the ground. I figured heck...since I need some form of turrets I might as well go ahead and make a full featured turret class since a lot of Torque developers seemed to need one. When I made that decision I did not realize how hard it would be to complete a full featured Turret class so I stupidly agreed to make one. You now have the result of that stupidity. Use it wisely.
If you have any questions email me at paul@crimsongames.com. I also idle in the #garagegames and #crimsongames channels on the irc.maxgaming.com IRC network.
#62
11/24/2005 (9:55 am)
i've figured out how to get the turret controlled by the mouse when it's mounted on a vehicle. click here
#63
The format for the console has changed in 1.3.
What used to be
Ari
01/01/2006 (8:13 pm)
@For TGE 1.3The format for the console has changed in 1.3.
What used to be
Con::addCommand("Trigger", "getNumObjects", cTriggerGetNumObjects, "[TriggerObject].getNumObjects()", 2, 2);
Con::addCommand("Trigger", "getObject", cTriggerGetObject, "[TriggerObject].getNumObjects(Object Index)", 3, 3);is nowConsoleMethod( Trigger, getNumObjects, S32, 2, 2, "")
{
return object->getNumTriggeringObjects();
}
ConsoleMethod( Trigger, getObject, S32, 3, 3, "(int idx)")
{
S32 index = dAtoi(argv[2]);
if (index >= object->getNumTriggeringObjects() || index < 0)
return -1;
else
return object->getObject(U32(index))->getId();
}and just below that you would add// phdana aiobject ->
ConsoleMethod( Trigger, setOwner, void, 3, 3, "(obj)")
{
if (argc > 2)
{
GameBase* owner = NULL;
if (Sim::findObject(argv[2], owner) == false)
return;
object->setOwner(owner);
}
}
// <- phdana aiobjectOr you could just cruise on over to Turret & AITurret classes, Version 1.20Ari
#64
In console i have a problem whit pojectile on shapeBase.cs
Thanks for all
02/21/2006 (12:09 pm)
I have this problem "my turrets don't shot!!!" ... help my please.....becoming crazy =PIn console i have a problem whit pojectile on shapeBase.cs
Thanks for all
#65
The turrets use "RifleProjectile" and "RifleExplosion" for the firing, but if you are using the starter.fps then you won't have those, so you need to go into GenericTurret.cs and change "RifleProjectile" and "RifleExplosion" to "CrossbowProjectile" and "CrossbowExplosion". Also, in your GenericTurretAI.cs you need to change "RifleExplosion" to "CrossbowExplosion".
Hope it works!
02/23/2006 (12:15 am)
Hey Cimo, Im having the same problem as you, BUT i found a fix.The turrets use "RifleProjectile" and "RifleExplosion" for the firing, but if you are using the starter.fps then you won't have those, so you need to go into GenericTurret.cs and change "RifleProjectile" and "RifleExplosion" to "CrossbowProjectile" and "CrossbowExplosion". Also, in your GenericTurretAI.cs you need to change "RifleExplosion" to "CrossbowExplosion".
Hope it works!
#66
02/23/2006 (2:13 am)
Nice!! GREAT!! =D thanks now all ok =D
#67
The second problem is when i dismount the normal turret, im somehow still "in" it, and can still control it even though im standing on the ground beside it?
Any help would be appreciated :D
02/23/2006 (11:02 am)
I've noticed a few other problems with this. The first being that after destroying an AI turret, i still collide with it (even though i cant see it) and if i delete it in F11, my game crashes.The second problem is when i dismount the normal turret, im somehow still "in" it, and can still control it even though im standing on the ground beside it?
Any help would be appreciated :D
#68
02/23/2006 (11:07 am)
I see a bug....If my player dead on turret and i shot firt deat.....Turret not stop to fire =P if on player sit on turret :D why?
#69
And the player just sits, because the creator thought it would look good :D
If you want to stop the sitting, just go into turrets.cs and search for "sitting" then comment out the line using // and it should stop him sitting.
02/24/2006 (12:13 am)
Oh yeah, i think there is a resource to stop the firing in the resource: Turret & AITurret classes, Version 1.20.And the player just sits, because the creator thought it would look good :D
If you want to stop the sitting, just go into turrets.cs and search for "sitting" then comment out the line using // and it should stop him sitting.
#70
And i use a turret...All ok..
But use a spacebar for dismount but my player jump and remaning on turret and don't move....
Help please.....THANKS
05/03/2006 (4:38 pm)
Hi....I have a problem....My AIturret don't shoot me......And i use a turret...All ok..
But use a spacebar for dismount but my player jump and remaning on turret and don't move....
Help please.....THANKS
#71
Have this problem....
On mount on my turret....the visual is not frontal...but lateral...I test to rotate in milkshape my turret and all ok...But i would rotate in torque in all grade and my player see always frontal.....
And is possible to evitate a press the spacebar to dismount and press any key? THANKS...plese help me!!
05/16/2006 (7:32 am)
I resolve all problem....But this impossible .... uff....Have this problem....
On mount on my turret....the visual is not frontal...but lateral...I test to rotate in milkshape my turret and all ok...But i would rotate in torque in all grade and my player see always frontal.....
And is possible to evitate a press the spacebar to dismount and press any key? THANKS...plese help me!!
#72
It would seem something is missing or wrong, I get errors relating to writePacketData declarations of the added code in turret.h and turret.cc.
I get the following errors.
Can anyone help.?
Many thanks in advance.
08/25/2006 (9:05 pm)
Does this work with version 1.4?.It would seem something is missing or wrong, I get errors relating to writePacketData declarations of the added code in turret.h and turret.cc.
I get the following errors.
1>------ Build started: Project: Torque Demo, Configuration: Debug Win32 ------ 1>Compiling... 1>turret.cc 1>c:\torque\sdk\engine\game\turrets\turret.h(175) : error C2555: 'Turret::writePacketData': overriding virtual function return type differs and is not covariant from 'ShapeBase::writePacketData' 1> c:\torque\sdk\engine\game\shapebase.h(1604) : see declaration of 'ShapeBase::writePacketData' 1>c:\torque\sdk\engine\game\turrets\turret.cc(656) : error C2440: 'initializing' : cannot convert from 'void' to 'bool' 1> Expressions of type void cannot be converted to other types 1>aiTurret.cc 1>c:\torque\sdk\engine\game\turrets\turret.h(175) : error C2555: 'Turret::writePacketData': overriding virtual function return type differs and is not covariant from 'ShapeBase::writePacketData' 1> c:\torque\sdk\engine\game\shapebase.h(1604) : see declaration of 'ShapeBase::writePacketData' 1>Generating Code... 1>Creating browse information file... 1>Microsoft Browse Information Maintenance Utility Version 8.00.50727 1>Copyright (C) Microsoft Corporation. All rights reserved. 1>Build log was saved at "file://c:\Torque\SDK\engine\out.VC8.DEBUG\BuildLog.htm" 1>Torque Demo - 3 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 6 up-to-date, 0 skipped ==========I have tried a full rebuild but still get the same and it all points to the new turret files.
Can anyone help.?
Many thanks in advance.
#73
11/02/2006 (4:55 pm)
I get the same errors with 1.4 I guess its just not compatible :(
#74
1.) I got a problem. Now that I added this code and can mount a turret and fire it. The bot and myself cannot take damage. The turret can take damage but not us.
2.) AI is not working at all for the turret.
Any suggestions as I dig back into it?
12/24/2006 (1:28 pm)
OK, I got this sorta working.1.) I got a problem. Now that I added this code and can mount a turret and fire it. The bot and myself cannot take damage. The turret can take damage but not us.
2.) AI is not working at all for the turret.
Any suggestions as I dig back into it?
#75
About the disappearing bug, I wonder if it can't be fixed by adding a LOSCol node to the shape. Or maybe forcing a render of a turret the Player is mounted to. Meh.
@ Peterjohn and Luke:
The writePacketData error comes from the fact that in turret.h, the method is defined as returning a boolean. However, in the .cc file, it returns void. Find the declaration of writePacketData in turret.h and change the return type (first word on the line) from bool to void. That should be the same for aiTurret, too.
05/17/2007 (11:59 am)
Integrated very nicely into TGE 1.5. Excellent work! Mind you, I get the disappearing at certain angles thing, and I haven't tested it with vehicles, but for now I'm impressed ;).About the disappearing bug, I wonder if it can't be fixed by adding a LOSCol node to the shape. Or maybe forcing a render of a turret the Player is mounted to. Meh.
@ Peterjohn and Luke:
The writePacketData error comes from the fact that in turret.h, the method is defined as returning a boolean. However, in the .cc file, it returns void. Find the declaration of writePacketData in turret.h and change the return type (first word on the line) from bool to void. That should be the same for aiTurret, too.
#76
I'm currently having trouble building this resource in TGE 1.5.
I followed your above suggestion by changing the Turret::writePacketData declaration to a void instead of bool in turret.h and aiTurret.h.
but I keep running into 4 compiler errors:
turret.cc
- turret.cc(656) : error C2440: 'initializing' : cannot convert from 'void' to 'bool'
Expressions of type void cannot be converted to other types
- turret.cc(662) : error C2562: 'Turret::writePacketData' : 'void' function returning a value
turret.h(139) : see declaration of 'Turret::writePacketData'
aiTurret.cc
- aiturret.cc(157) : error C2440: 'initializing' : cannot convert from 'void' to 'bool'
Expressions of type void cannot be converted to other types
- aiturret.cc(159) : error C2562: 'AITurret::writePacketData' : 'void' function returning a value
aiturret.h(80) : see declaration of 'AITurret::writePacketData'
I found the lines that were causing this error and commented them out and was able to build the project correctly. But the turrets did not work in game. The models could be placed but running into the turret did not mount the character to the turret.
the code i commented was:
//bool flag = Parent::writePacketData(con, stream);
//return flag;
in void Turret::writePacketData()
and the same for void AITurret::writePacketData()
I'm am still kinda new to Torque so I'm not sure exactly what those lines of code do. And I'm not sure why a function declared void would return a bool value.
Any help would be greatly appreciated :)
And thanks for the great resource Paul!
07/07/2007 (9:25 pm)
@DanielI'm currently having trouble building this resource in TGE 1.5.
I followed your above suggestion by changing the Turret::writePacketData declaration to a void instead of bool in turret.h and aiTurret.h.
but I keep running into 4 compiler errors:
turret.cc
- turret.cc(656) : error C2440: 'initializing' : cannot convert from 'void' to 'bool'
Expressions of type void cannot be converted to other types
- turret.cc(662) : error C2562: 'Turret::writePacketData' : 'void' function returning a value
turret.h(139) : see declaration of 'Turret::writePacketData'
aiTurret.cc
- aiturret.cc(157) : error C2440: 'initializing' : cannot convert from 'void' to 'bool'
Expressions of type void cannot be converted to other types
- aiturret.cc(159) : error C2562: 'AITurret::writePacketData' : 'void' function returning a value
aiturret.h(80) : see declaration of 'AITurret::writePacketData'
I found the lines that were causing this error and commented them out and was able to build the project correctly. But the turrets did not work in game. The models could be placed but running into the turret did not mount the character to the turret.
the code i commented was:
//bool flag = Parent::writePacketData(con, stream);
//return flag;
in void Turret::writePacketData()
and the same for void AITurret::writePacketData()
I'm am still kinda new to Torque so I'm not sure exactly what those lines of code do. And I'm not sure why a function declared void would return a bool value.
Any help would be greatly appreciated :)
And thanks for the great resource Paul!
#77
change
//bool flag = Parent::writePacketData(con, stream);
to
Parent::writePacketData(con, stream);
and leave the return commented out.
@Paul .... outstanding contribution, thank you.
07/14/2007 (3:21 am)
@Billchange
//bool flag = Parent::writePacketData(con, stream);
to
Parent::writePacketData(con, stream);
and leave the return commented out.
@Paul .... outstanding contribution, thank you.
#78
I uploaded a patch to apply on a clean 1.4.2 TGE install on my website here, and I left this resource's code commented out.
Can you give me some hints on what I done wrong? Thanks in advance for anything.
Bye, Berserk.
.
09/11/2007 (5:46 pm)
Hello. I had some troubles using this resource in my project (see here for details).I uploaded a patch to apply on a clean 1.4.2 TGE install on my website here, and I left this resource's code commented out.
Can you give me some hints on what I done wrong? Thanks in advance for anything.
Bye, Berserk.
.
#79
EDIT, months later.....: Never mind, I just accidentally didnt copy Trigger::setOwner to the right file....I accidentally copied it into the header file. D'oh!
09/29/2007 (12:12 pm)
I'm also getting the linkage error. Tried rebuilding, it didn't fix it. Has anybody resolved this issue, or is it fixed in the update resource?EDIT, months later.....: Never mind, I just accidentally didnt copy Trigger::setOwner to the right file....I accidentally copied it into the header file. D'oh!
#80
turret.h:
class Trigger : public GameBase
{
...
SimObjectPtr mOwner;
turret.cc/cpp:
void Trigger::potentialEnterObject(GameBase* enter)
{
...
if (!mOwner.isNull())
12/18/2007 (9:02 am)
It should be noted that the line if (mOwner != NULL) doesn't quite work right when operating on a turret mounted to a vehicle. that needs changing to the following:turret.h:
class Trigger : public GameBase
{
...
SimObjectPtr
turret.cc/cpp:
void Trigger::potentialEnterObject(GameBase* enter)
{
...
if (!mOwner.isNull())

Torque Owner Simon Engler