Game Development Community

WaterCraft resource quickport to TGEA

by Ross Pawley · in Torque Game Engine Advanced · 08/05/2007 (5:35 am) · 1 replies

So I finally got a new monitor for my computer at home, and managed to do a quick port of the Ken Finney's WaterCraft resource to TGEA. Currently the only issue is that the gravity calculation is wrong because for some reason the Rigid's force is getting a positive z of 20, which negates the gravity (since -20, downward z, is the vehicle gravity). So at the moment, the boat won't sink onto the water properly, and will stay floating in mid air, and will float/fly if you hit anything or turn it upward. I'm not sure at this point where that's coming from, but hopefully someone can point it out and this will be working correctly. However, it does build and run, so I suppose it's worth a quick post since no one else has done it.

There were really only a couple of changes needed to get this to work. Basically a couple of different includes, a change to one of the ParticleEngine vs. ParticleEmitter variables and blammo, it's golden.

The header should be exactly the same. You'll need to change the smoke particle's texture in the zodiac.cs to something that actually exists in the TGEA version of the starter.fps. Also, the only line that's needed in player.cs is the extra if for Armor::onCollision.

First, grab the resource: www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2299

In player.cs change
if ((%this.className $= WheeledVehicleData) && %obj.mountVehicle &&
         %obj.getState() $= "Move" && %col.mountable)

to

if ((%this.className $= WheeledVehicleData || 
     %this.classname $= WaterCraftData) && %obj.mountVehicle &&
         %obj.getState() $= "Move" && %col.mountable)

Change the top of waterCraft.cpp (.cc in the resource...) to
//-----------------------------------------------------------------------------
// Torque Game Engine
// 
// Copyright (c) 2001 GarageGames.Com
// Portions Copyright (c) 2001 by Sierra Online, Inc.
//-----------------------------------------------------------------------------
 
#include "game/vehicles/WaterCraft.h"
 
#include "core/bitStream.h"
#include "sceneGraph/sceneState.h"
#include "collision/clippedPolyList.h"
#include "collision/planeExtractor.h"
#include "game/moveManager.h"
#include "ts/tsShapeInstance.h"
#include "console/consoleTypes.h"
#include "terrain/terrData.h"
#include "sceneGraph/sceneGraph.h"
#include "audio/audio.h"
#include "game/fx/particleEmitter.h"
#include "math/mathIO.h"
#include "materials/materialPropertyMap.h"
#include "terrain/waterBlock.h"
 
IMPLEMENT_CO_DATABLOCK_V1(WaterCraftData);
IMPLEMENT_CO_NETOBJECT_V1(WaterCraft);
 
namespace {
 
const U32 sIntergrationsPerTick = 1;
const F32 sWaterCraftGravity  = -20;
 
const U32 sCollisionMoveMask = (TerrainObjectType        | InteriorObjectType   |
                                       WaterObjectType          | PlayerObjectType     |
                                       StaticShapeObjectType    | VehicleObjectType    |
                                       VehicleBlockerObjectType | StaticTSObjectType   |
                                       AtlasObjectType);

Then, find all instances of "mRigid.state." and replace with just "mRigid.". Next, find all instances of "ParticleEngine::PC_COLOR_KEYS" to "ParticleData::PDC_NUM_KEYS" (not sure if that's exactly correct, but it works...).

That's basically it.

If anyone finds where the gravity is being calculated wrong/weirdly that gives that positive z force, let me know please :)

#1
08/06/2007 (2:41 am)
If anyone's interested, I managed to fix up the gravity somewhat by 1) including the mass in the initial gravity force and buioyancy calculations (i.e., * mRigid.mass in each of those) as well as the spring force (which, is best used if you take out the raycast against the terrain and do it only for water).

So here's the new spring force:

force += (springForce + springDamping) * mRigid.mass;

Gravity:

force += Point3F(0, 0,sWaterCraftGravity * mGravityMod * mRigid.mass);
force += Point3F(0, 0,-mBuoyancy * sWaterCraftGravity * mGravityMod * mRigid.mass);

There are still collision issues with the terrain, but a possible fix may be to detect when near/in contact with terrain and slow down the craft (for traditional boats).