Game Development Community

Ai not spawning...

by Lane Anderson · in Torque Game Engine · 04/04/2005 (3:10 pm) · 10 replies

Hey,


I'm trying to get an Ai controlled vehicle into my game, but it doesn't seem to be working. Here's the modified parts of the aiplayer.cs file(all I did was modify it to use a vehicle datablock instead of the player one; I'm using the starter.racing as the basis for my game):


//-----------------------------------------------------------------------------
// Demo Pathed AIPlayer.
//-----------------------------------------------------------------------------

datablock WheeledVehicleData(DemoPlayer : DefaultCar)
{
shootingDelay = 2000;
};



//-----------------------------------------------------------------------------
// AIPlayer static functions
//-----------------------------------------------------------------------------

function AIPlayer::spawn(%name,%spawnPoint)
{
// Create the demo player object
%player = new AiPlayer() {
dataBlock = DemoPlayer;
path = "";
};
MissionCleanup.add(%player);
%player.setShapeName(%name);
%player.setTransform(%spawnPoint);
return %player;
}

function AIPlayer::spawnOnPath(%name,%path)
{
// Spawn a player and place him on the first node of the path
if (!isObject(%path))
return;
%node = %path.getObject(0);
%player = AIPlayer::spawn(%name,%node.getTransform());
return %player;
}


function AIManager::spawn(%this)
{
%player = AIPlayer::spawnOnPath("Bubba","MissionGroup/Paths/Path1");
%player.followPath("MissionGroup/Paths/Path1",-1);

//%player.mountImage(CrossbowImage,0);
//%player.setInventory(CrossbowAmmo,1000);
return %player;
}



I have a Path names "Path1" under "Paths" in the mission editor, and iIve double checked the datablock, yet no car spawns in my game.


???


Thanks,


Lane

#1
04/04/2005 (3:17 pm)
Have you looked at the console for any errors?

Off the top of my head, I don't see a shapeFile definition in your datablock, although it -may- be in your DefaultCar datablock.

Also, you are dropping in a wheeled vehicle into AI code designed for a playerData type object. There may (or may not!) be issues involved with that as well.
#2
04/04/2005 (3:26 pm)
Yes, and I see none. And heres the car Datablock(with the shapefile def) just in case theres something wrong I'm missing:

datablock WheeledVehicleData(DefaultCar)
{
category = "Vehicles";
shapeFile = "~/data/shapes/buggy/buggy.dts";
emap = true;

maxDamage = 1.0;
destroyedLevel = 0.5;

maxSteeringAngle = 0.785; // Maximum steering angle, should match animation
tireEmitter = TireEmitter; // All the tires use the same dust emitter

// 3rd person camera settings
cameraRoll = false; // Roll the camera with the vehicle
cameraMaxDist = 7; // Far distance from vehicle
cameraOffset = 1.5; // Vertical offset from camera mount point
cameraLag = 0.0; // Velocity lag of camera
cameraDecay = 0.75; // Decay per sec. rate of velocity lag

// Rigid Body
mass = 300;
massCenter = "0 -0.5 0"; // Center of mass for rigid body
massBox = "0 0 0"; // Size of box used for moment of inertia,
// if zero it defaults to object bounding box
drag = 0.6; // Drag coefficient
bodyFriction = 0.6;
bodyRestitution = 0.4;
minImpactSpeed = 5; // Impacts over this invoke the script callback
softImpactSpeed = 5; // Play SoftImpact Sound
hardImpactSpeed = 15; // Play HardImpact Sound
integration = 4; // Physics integration: TickSec/Rate
collisionTol = 0.1; // Collision distance tolerance
contactTol = 0.1; // Contact velocity tolerance

// Engine
engineTorque = 8000; // Engine power
engineBrake = 600; // Braking when throttle is 0
brakeTorque = 8000; // When brakes are applied
maxWheelSpeed = 60; // Engine scale by current speed / max speed

// Energy
maxEnergy = 100;
jetForce = 3000;
minJetEnergy = 30;
jetEnergyDrain = 2;


// Sounds
// jetSound = ScoutThrustSound;
// engineSound = BuggyEngineSound;
// squealSound = ScoutSquealSound;
// softImpactSound = SoftImpactSound;
// hardImpactSound = HardImpactSound;
// wheelImpactSound = WheelImpactSound;

// explosion = VehicleExplosion;
};
#3
04/04/2005 (3:42 pm)
Ummm, correct me if I'm wrong but isn't AIPlayer dependant upon PlayerData?
#4
04/04/2005 (3:53 pm)
I don't think %player would work for vehicles it would probably be %wheeledvehicle maybe, thats not very specific though.
#5
04/04/2005 (8:48 pm)
It won't work that way. An AIPlayer is an object that derives (inherits) from Player. A vehicle is another branch of the tree. You can't just create an AIPlayer and set it to a vehicle datablock.

What you can do is create an AIPlayer and MOUNT it to a vehicle. This is discussed on This Resource
#6
04/04/2005 (9:12 pm)
You could probably also create an AIPlayer datablock and just set the shapefile to your car.dts
#7
04/05/2005 (8:19 am)
Wouldn't that prevent any wheels from being automagically created?? Because any wheeledVehicle.dts wouldn't have the wheels attached until code takes over...?!? Bruno's got the right idea...
#8
04/05/2005 (1:53 pm)
Thanks for the link Bruno, looks like that's what I'll need.
#9
04/05/2005 (2:06 pm)
@Rex, Personally I would just mount the wheels in code at creation, just like you would mount a weapon.
#10
04/07/2005 (8:13 am)
@Dreamer,

But you still wouldn't have the physics. The resource isn't that hard to implement and it solves most of the problems.