Game Development Community

Vehicle Collision

by Steven Jackson · in Torque Game Engine · 01/25/2004 (8:48 pm) · 9 replies

I've been trying to get my FlyingVehicle to collide with the interiors with "F" on them from the Torque Tutorial Base, and cause damage to the vehicle. It collides fine with them, but the problem is, it doesn't damage it. I'm new to the engine, so I'm not familiar with the whole system yet. I have functions for Ship::onDamage and Ship::onCollision. In each one I've got an echo writing random stuff to the console if it is called. It never writes anything to the console, so I'm assuming onCollision/onDamage are never being called. Here's my onCollision:

function Ship::onCollision(%this,%obj,%col,%vec,%speed)
{
   echo("Ship::onCollision called");
}

#1
01/25/2004 (9:17 pm)
Are you sure that the namespace is Ship? What does the datablock for your ship look like?

Oh yeah - events often hang off the datablock, not the instance name, too.
#2
01/25/2004 (9:48 pm)
I'd start with the vehicle class first, wheeledvehicle::onCollision / flyingvehicle::onCollision, etc.

Even if you don't put anything other then an echo, you sometimes need those functions to be able to use the Scout::onCollision type functions.
#3
01/25/2004 (10:08 pm)
I checked over all my naming, and everything looks right to me. Here is most of Ship.cs:
datablock FlyingVehicleData(Ship)
{
	spawnOffset                   = "0 0 2";
	emap                          = true;
	category                      = "Vehicles";
	shapeFile	                     = "~/data/shapes/vehicles/aircraft.dts";
	multipassenger                = false;
	computeCRC                    = true;

	drag                          = 0.15;
	density                       = 0.0;

	mountPose[0]                  = sitting;
	mountable                     = true;
	numMountPoints                = 1;
	isProtectedMountPoint[0]      = true;
	cameraMaxDist                 = 0.5;
	cameraOffset                  = 4.5;
	cameraLag	                     = 0.0;
	cameraRoll = false;
 	useEyePoint = false;

	explosionDamage               = 10.5;
	explosionRadius               = 15.0;

	maxDamage                     = 50.40;
	destroyedLevel                = 50.40;
									
	isShielded                    = true; 
	energyPerDamagePoint          = 160;
	maxEnergy	                     = 280;       
	rechargeRate                  = 0.8;

	minDrag                       = 30;       
	rotationalDrag                = 10;        

	maxAutoSpeed                  = 10; 
	autoAngularForce              = 200;       
	autoLinearForce               = 200;     
	autoInputDamping              = 0.95;     
	integration                   = 6;                     
	collisionTol                  = 0.2;                          
	contactTol                    = 0.1;

	maxSteeringAngle              = 2;         
	horizontalSurfaceForce        = 6;         
	verticalSurfaceForce          = 4;         
	maneuveringForce              = 2400;      
	steeringForce                 = 70;        
	steeringRollForce             = 10;        
	rollForce	                     = 80;        
	hoverHeight                   = 45;        
	createHoverHeight             = 45;        
	maxForwardSpeed               = 60;        
	jetForce                      = 3000;      
	minJetEnergy                  = 28;        
	jetEnergyDrain                = 2.8;       
                                                                                                                                                                                                                      
	vertThrustMultiple            = 3.0;

	mass                          = 30;    
	bodyFriction                  = 0;     
	bodyRestitution               = 1.0;       
	minRollSpeed                  = 2000; 
	softImpactSpeed               = 3;         
	hardImpactSpeed               = 15;        

	minImpactSpeed                = 1;         
	speedDamageScale              = 0.66;

	collDamageThresholdVel        = 23.0;
	collDamageMultiplier          = 0.02;

	minTrailSpeed                 = 15;
	
	triggerDustHeight             = 4.0;
	dustHeight                    = 1.0;

	damageEmitterOffset[0]        = "0.0 -3.0 0.0 ";
	damageLevelTolerance[0]       = 0.3;
	damageLevelTolerance[1]       = 0.7;
	numDmgEmitterAreas	            = 3;

	minMountDist                  = 2;

	checkRadius                   = 5.5;
	observeParameters             = "0 0 0";
									
	shieldEffectScale             = "0.937 1.125 0.60";
};
  

function Ship::onDamage(%this, %obj, %delta)
{
	echo("Ship::onDamage called");
	Parent::onDamage(%this, %obj);
	%currentDamage = %obj.getDamageLevel();
 
	if(%currentDamage > %obj.destroyedLevel)
	{
		if(%obj.getDamageState() !$= "Destroyed")
		{
			if(%obj.respawnTime !$= "")
				%obj.marker.schedule = %obj.marker.data.schedule(%obj.respawnTime, "respawn", %obj.marker); 
			%obj.setDamageState(Destroyed);
		}
	}
	else
	{
		if(%obj.getDamageState() !$= "Enabled")
			%obj.setDamageState(Enabled);
	}
 
    %obj.client.setHealthAmountHud(%this.maxDamage - %obj.getDamageLevel() );
}

After the onDamage is the onCollision function I posted previously.
#4
01/26/2004 (4:16 am)
As Harold pointed out, try:

function FlyingVehicle::onCollision(%this,%obj,%col,%vec,%speed){   echo("Ship::onCollision called");}
#5
01/26/2004 (4:18 am)
I'm still waking up, so forgive me, but shouldn't there be a "className" in there?
#6
01/26/2004 (9:45 am)
That's only really in scriptobjects. Good thought tho.
#7
01/26/2004 (10:59 am)
function FlyingVehicleData::onCollision(%this,%obj,%col,%vec,%speed)

function WheeledVehicleData::onCollision(%this,%obj,%col,%vec,%speed)

function HoverVehicleData::onCollision(%this,%obj,%col,%vec,%speed)
SHould all work fine


you forgot the "Data" bit thats required ;)
#8
01/26/2004 (6:40 pm)
Hey, thanks for all your help. I fixed it by giving it a different className, and then creating an "onImpact", not an "onCollision". Then I added a ::damage() function, and it's working great!
#9
03/30/2004 (11:50 am)
Steven Jackson, could you post the script, I'm doing something similar but with futuristic cars... and I can't get it working. correctly. Thanks! (I'll post back with what I have so far based on information in this thread and in others)