Adding Watercraft to TGE
by Ken Finney · 03/06/2002 (11:36 am) · 45 comments
Download Code File
Adding a Watercraft class
Adding a Watercraft class
[b]General[/b]
I've created a Watercraft class, which is quite parallel to the HoverVehicle class.
Someone with more time may want to change this to actually derive Watercraft
from Hovercraft properly. I didn't, since I wasn't sure where I was going to
go with it, until I got there. The Zodiac rubber boat is used as an instance
of a Watercraft.
To add the Watercraft class, and get a functioning boat into your game,
you need to do the following:
A) Download the latest Head release of TGE.
B) Incorporate the Watercraft class files into your engine project.
C) Add a Watercraft control script & vehicle model to your game.
D) Add Watercraft/zodiac support statements to existing scripts.
E) Modify the Collision and Dismount code to accommodate the Watercraft.
F) Test the Zodiac by running the game and inserting the boat with
the Editor.
[b]Procedure[/b]
[b]A)[/b] If you do not have it, download the latest Head release of TGE.
Once you have that working, you can then add the WaterCraft class,
with some minor modifications. These modifications are made against
the Head (which includes the racing demo).
[b]B)[/b] Incorporating the class files into your engine project.
1) Download the 'WaterCraft.zip' file, and extract 'WaterCraft.cc' and
'Watercraft.h' to the engine directory: engine\game\vehicles.
2) Add 'WaterCraft.cc' to your engine project in the game:vehicles project folder
(you can add 'WaterCraft.h' to your project as well, but it isn't
necessary).
3) Rebuild your project.
[b]C)[/b] Add the Watercraft control script & vehicle model.
1) Extract the file 'zodiac.cs' from 'WaterCraft.zip' into the game directory:
fps\server\scripts.
2) Create a directory named 'fps\data\shapes\zodiac'.
3) Extract the archive file 'zodiac.zip' from the 'WaterCraft.zip' archive.
4) Extract the shape file 'zodiac.dts' from 'zodiac.zip' into the new game directory:
fps\data\shapes\zodiac.
5) Extract the skin files: 'motorbase.png', 'motortop'.png, 'rubber.png', 'transoms.png' and
'prop.png' into the new game directory: fps\data\shapes\zodiac.
[b]D)[/b] Add Watercraft/zodiac support statements to existing scripts.
1) in the script 'fps\server\script\sgame.cs' add
exec("./Zodiac.cs");
to the function 'createGame();' after the last 'exec' statement.
[b]E)[/b] Modify the Collision and Dismount code to accommodate the Watercraft.
1) In the file 'fps\server\scripts\player.cs' find the conditional that
tests for vehicle type in the Armor::onCollision method:
if ((%this.className $= WheeledVehicleData ) && %obj.mountVehicle &&
%obj.getState() $= "Move" && %col.mountable) {
and change it to this:
[b]
if ((%this.className $= WheeledVehicleData ||
%this.className $= WaterCraftData) && %obj.mountVehicle &&
%obj.getState() $= "Move" && %col.mountable) {
[/b]
This checks for the Watercraft data type to allow for mounting them.
2) In the same file, find the Armor::doDismount method (just above onCollision)
and locate the following section:
if (%forced && %success == -1)
%pos = %oldPos;
%obj.mountVehicle = false;
%obj.schedule(4000, "MountVehicles", true);
and change it to this:
[b]
if (%forced && %success == -1)
%pos = %oldPos;
%obj.unmount();
%obj.setControlObject(%obj);
if(%obj.mVehicle)
{
%obj.mVehicle.getDataBlock().playerDismounted(%obj.mVehicle, %obj);
%obj.mVehicle.mountable = true;
}
%obj.mountVehicle = false;
%obj.schedule(4000, "MountVehicles", true);
[/b]
Note: the collision & mount/dismount code is based on the tutorial
provided by Badguy, found in the GG Resources.
[b]F)[/b] Test the Zodiac by running the game and inserting the boat with
the Editor.
1) Start a mission that has plenty of water in it.
2) Use the World Editor Creator (F11, F4) and select the
Zodiac from the list of Shapes->Vehicles.
3) Depending on how you have things set in your world, when you
place the boat, it should spawn just a few metres above the
water, then slowly settle into it. If you have wave action set on,
you may see the boat get swamped, then bob back up slowly.
4) Run and jump into the boat to mount, or place the camera over the
boat and use F7 to drop the player in from the camera position.
5) Use your WASD action keys to control boat speed, use the mouse to
control direction.
6) Experiment with the settings in the datablock in 'Zodiac.cs' to adjust
it's movement behaviour, beaching capabilities and so on.
There is a posting in the SDK forums from a fellow about how to synchronize
with the wave action correctly, but I can't find it ...About the author
#2
03/05/2002 (1:38 pm)
which link is broken ?
#3
03/05/2002 (4:16 pm)
'MountVehicles' change made, but I don't see any broken links ...
#4
03/05/2002 (10:32 pm)
Pretty cool mr Finney. sorry if i was a bit childish before, with my posts about crappy this and that. after i posted i went and read your profile. educated much? sheesh, you should post a warning before that thing "caution, read only if unintimidated by geniuses" 8P
#5
03/06/2002 (5:26 pm)
This is nice, but isn't there some way to make it so the boat doesn't just sink slowly? When the boat goes into the air, it should fall down pretty fast...
#6
03/06/2002 (10:00 pm)
Yes Marko, All these things can be tweaked in the script; stuff like gravity, density, water desnity, and so on. It used to drop into the water with a splash and then bob up, but something has changed, and I haven't had time to track it down yet...
#7
"Unable to find function WaterCraftData::create()" ...
Any ideas? :-(
03/07/2002 (10:35 am)
Hm, doesn't work for me... I've got the HEAD version from 03/06/2002, I've completed every step of the tutorial and I get the error "Unable to find function WaterCraftData::create()" ...
Any ideas? :-(
#8
03/07/2002 (10:55 am)
Okay, I've simply addedfunction WaterCraftData::create(%block)
{
%obj = new WaterCraft() {
dataBlock = %block;
};
return(%obj);
}to the cs file and now I get the boat, but I'm not able to use it... how do I mount it? Or is it not fully implemented yet?
#9
It wasn't set moutable initially... Now it works :-)
Cool stuff!! But I guess I have to do something with the collision code... ;-) Fly, little boat, fly...
03/07/2002 (12:48 pm)
Aaahhhh, THERE you go...function WaterCraftData::create(%block)
{
%obj = new WaterCraft() {
dataBlock = %block;
};
%obj.mountable = true;
return(%obj);
}It wasn't set moutable initially... Now it works :-)
Cool stuff!! But I guess I have to do something with the collision code... ;-) Fly, little boat, fly...
#10
03/07/2002 (4:15 pm)
Thanks Stefan. What I had done is include the ::create method in my vehicles.cs, and missed that fact when preparing the above. I've moved that method into zodiac.cs at the end, and re-uploaded the watercraft.zip with this alteration, so the problem should be gone now.
#11
03/08/2002 (10:42 am)
Tried it, it works, but the boat does not behave very...well....boaty. Riding waves, etc. Overall it is good though because there are water vehicles where where were none before :)
#12
But the waves cross the boat with default setting.
What is the solution.
04/04/2002 (8:14 am)
It's running,But the waves cross the boat with default setting.
What is the solution.
#13
02/15/2003 (10:15 pm)
Why didn't you just use the HoverVehicle class? When I diffed the classes they looked damn near the same. I just changed your script to create a hovercraft and it seemed to work fine. I am a newbie so is there something that I am missing? {C8
#14
02/16/2003 (8:30 am)
#15
I'm working around your watercraft to enhance the multi-mounting capabilities.
I have some problem with the meaning of each parameter and their range to tune the value to properly ship type, weight, size etc... Can you help me?
Paolo.
02/19/2003 (12:06 am)
Hi Kan,I'm working around your watercraft to enhance the multi-mounting capabilities.
I have some problem with the meaning of each parameter and their range to tune the value to properly ship type, weight, size etc... Can you help me?
Paolo.
#16
Any help would be appreciated. 90% of them seem to stem from changes to "Rigid" in that it no longer has a "state" member variable. That is directly or indireclty responsible for the majority of these errors. I'm not sure what the changes to Rigid are to modifiy this.
Compiling...
WaterCraft.cc
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(37) : error C2065: 'ForceFieldObjectType' : undeclared identifier
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(533) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(533) : error C2228: left of '.linVelocity' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(533) : error C2228: left of '.len' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(559) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(559) : error C2228: left of '.getTransform' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(577) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(577) : error C2228: left of '.linVelocity' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(594) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(594) : error C2228: left of '.linVelocity' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(659) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(659) : error C2228: left of '.linVelocity' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(659) : error C2228: left of '.len' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(666) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(666) : error C2228: left of '.linVelocity' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(673) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(673) : error C2228: left of '.angMomentum' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(748) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(748) : error C2228: left of '.linVelocity' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(763) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(763) : error C2228: left of '.linVelocity' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(764) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(764) : error C2228: left of '.angMomentum' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(766) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(766) : error C2228: left of '.force' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(767) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(767) : error C2228: left of '.torque' must have class/struct/union type
10/23/2003 (4:04 pm)
I know this is old, but i'm hoping someone can help me. I'm getting a bunch of compile errors with this. Obvously the problem is due to changes in Torque, but I still don't know the engine weel enogh to make the changes.Any help would be appreciated. 90% of them seem to stem from changes to "Rigid" in that it no longer has a "state" member variable. That is directly or indireclty responsible for the majority of these errors. I'm not sure what the changes to Rigid are to modifiy this.
Compiling...
WaterCraft.cc
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(37) : error C2065: 'ForceFieldObjectType' : undeclared identifier
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(533) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(533) : error C2228: left of '.linVelocity' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(533) : error C2228: left of '.len' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(559) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(559) : error C2228: left of '.getTransform' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(577) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(577) : error C2228: left of '.linVelocity' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(594) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(594) : error C2228: left of '.linVelocity' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(659) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(659) : error C2228: left of '.linVelocity' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(659) : error C2228: left of '.len' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(666) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(666) : error C2228: left of '.linVelocity' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(673) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(673) : error C2228: left of '.angMomentum' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(748) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(748) : error C2228: left of '.linVelocity' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(763) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(763) : error C2228: left of '.linVelocity' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(764) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(764) : error C2228: left of '.angMomentum' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(766) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(766) : error C2228: left of '.force' must have class/struct/union type
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(767) : error C2039: 'state' : is not a member of 'Rigid'
../engine\game/rigid.h(25) : see declaration of 'Rigid'
C:\torque_head\torque\engine\game\vehicles\WaterCraft.cc(767) : error C2228: left of '.torque' must have class/struct/union type
#17
For future reference if anyone has this problem, change all instances of "mRigid.state.blah" to "mRigid.blah" removing the "state" member which no longer exists. Also simply remove the "ForceFieldObjectType" mask. This apparently is not used anymore.
I am not sure how these changes affect the watercraft, if at all since I never saw it working before. But so far it seems to be fine.
10/24/2003 (9:35 am)
Ok after digging through torque a bit, I managed to get this working.For future reference if anyone has this problem, change all instances of "mRigid.state.blah" to "mRigid.blah" removing the "state" member which no longer exists. Also simply remove the "ForceFieldObjectType" mask. This apparently is not used anymore.
I am not sure how these changes affect the watercraft, if at all since I never saw it working before. But so far it seems to be fine.
#18
DISCONECT
You do not have the correct version of the FPS
starter kit or the related art needed to play on
this server, please contact the server operator
for more information. (Missing particle texture:
starter.fps/data/shape/smokeParticle)
Please help. I work befor I added the watercraft stuff so I know I've messed up somewhere. Has anyone gotten this error before.
12/04/2003 (4:04 pm)
I've done evrything right, but when I try to load "Stronghold" it says:DISCONECT
You do not have the correct version of the FPS
starter kit or the related art needed to play on
this server, please contact the server operator
for more information. (Missing particle texture:
starter.fps/data/shape/smokeParticle)
Please help. I work befor I added the watercraft stuff so I know I've messed up somewhere. Has anyone gotten this error before.
#19
12/06/2003 (9:14 am)
You either need to add a texture by that name in that folder or change the textureName links in zodiac.cs to point to a texure you want for the smoke emitter
#20
Thanks to all those who help.
12/08/2003 (2:28 pm)
Ok everything is working fine now. I've looked at the code, how can I adjust the gravity and bouancy settings? Is it in the .cc file or .cs script? My boat goes airborne or submerges till it hits land is this normal. Can anyone help on fixing this problem? Also what dummy objects, besides bounds, do I need to include in a .dts file if I wanted to make another boat? Is there an included rudder control somewhere? Sorry for all the questions I'm a newbie.Thanks to all those who help.
Torque 3D Owner Xavier "eXoDuS" Amado
Default Studio Name
%obj.schedule(4000, "setMountVehicle", true);
should really be:
%obj.schedule(4000, "MountVehicles", true);
and link is br0ken :\