Game Development Community

Flying Vehicle Move To?

by Devin Golberg · in Torque Game Engine · 12/18/2009 (1:53 pm) · 0 replies

Hello everyone,

I'm a bit new to the whole TorqueGameEngine, but I have had two classes in which we used TGE. I've setup a space style flight game and am having some troubles with controlling the vehicle. Currently I've got it setup so that they player enters the ship immediately after spawning and then the ship is placed at the starting point inside of a station's "hanger" area. Anytime the player ship enter's the hanger area, a trigger activates a store gui where the player can make modifications to their ship.

The problem I'm having is, I need to take control of the ship away from the player when the store gui opens, and restore control to the player upon exitting the store gui. I also need the ship to move to a designated marker when the player enters the trigger and stop at the marker.

My current code for the flying vehicle is as follows:


datablock FlyingVehicleData(FLYINGVEHICLE)
{
spawnOffset = "0 0 0";
emap = true;
shapeFile = "~/data/shapes/ship/chassis01.dts";

multipassenger = false;
computeCRC = true;

drag = 0.25;
density = 1.0;

// jetNozzle1 = playerWeaponExplosionParticle;

// Camera Settings
cameraOffset = 1.5; // Vertical offset from camera mount point
cameraMaxDist = 10;
cameraOffset = 0.5;
cameraLag = 0.1;
cameraDecay = 1;
cameraRoll = true; // Roll the camera with the vehicle


minDrag = 80; // Linear Drag (eventually slows you down when not thrusting...constant drag)
rotationalDrag = 80; // Anguler Drag (dampens the drift after you stop moving the mouse...also tumble drag)

maxAutoSpeed = 2; // Autostabilizer kicks in when less than this speed. (meters/second)
autoAngularForce = 900; // Angular stabilizer force (this force levels you out when autostabilizer kicks in)
autoLinearForce = 300; // Linear stabilzer force (this slows you down when autostabilizer kicks in)
autoInputDamping = 0.55; // Dampen control input so you don't` whack out at very slow speeds

// Maneuvering

maxSteeringAngle = .5; // Max radiens you can rotate the wheel. Smaller number is more maneuverable.
horizontalSurfaceForce = 20; // Horizontal center "wing" (provides "bite" into the wind for climbing/diving and turning)
verticalSurfaceForce = 20; // Vertical center "wing" (controls side slip. lower numbers make MORE slide.)
maneuveringForce = 2700; // Horizontal jets (W,S,D,A key thrust)
steeringForce = 4000; // Steering jets (force applied when you move the mouse)
steeringRollForce = 1000; // Steering jets (how much you heel over when you turn)
rollForce = 900; // Auto-roll (self-correction to right you after you roll/invert)
//hoverHeight = 1.5; // Height off the ground at rest
//createHoverHeight = 0.5; // Height off the ground when created
maxForwardSpeed = 10; // speed in which forward thrust force is no longer applied (meters/second)

// Rigid body
mass = 200; // Mass of the vehicle //Controls how easily the ship turns
integration = 3; // Physics integration: TickSec/Rate
collisionTol = 0.6; // Collision distance tolerance
contactTol = 0.4; // Contact velocity tolerance

bodyFriction = 0; // Don't mess with this.
bodyRestitution = 0.8; // When you hit the ground, how much you rebound. (between 0 and 1)
minRollSpeed = 2000; // Don't mess with this.

checkRadius = 5.5;
observeParameters = "0 0 0";
};

datablock ItemData( FLYINGVEHICLEPICKUP )
{
shapefile = "~/data/shapes/ship/chassis01.dts";
emap = true;
scale = ".5 .5 .5";
gravityMod = "0.0";
};

function makeflyingpickup(%position)
{
%newSHAPENAME = new item()
{
datablock = FLYINGVEHICLEPICKUP;
position = %position;
gravityMod = "0.0";

static = true;
rotate = false;
};
}

function makeFLYINGVEHICLE( )
{
// get client
%client = $player.client;

// create vehicle
$FLYINGVEHICLE = new flyingVehicle(PlayerShip) {
dataBlock = FLYINGVEHICLE;
client = %client;
scale = ".5 .5 .5";
gravityMod = "0.0";
};

$FLYINGVEHICLE.setTransform( $player.getTransform() );

// set glider as player
%client.player = $FLYINGVEHICLE;
%client.setControlObject($FLYINGVEHICLE);


// delete old player
$FLYINGVEHICLE.client = %client;

$FLYINGVEHICLE.playThread( 0, root );
$FLYINGVEHICLE.applyImpulse( $FLYINGVEHICLE.getPosition(), "0 0 100");


%newSHAPENAME = new StaticShape(wingobject1)
{
datablock = Wing01;
position = "0 0 0";
};

$FLYINGVEHICLE.mountObject(WingObject1, 1);
%newSHAPENAME = new StaticShape(wingobject2)
{
datablock = Wing02;
position = "0 0 0";
};

$FLYINGVEHICLE.mountObject(WingObject2, 0);
$player.delete();
}

datablock StaticShapeData( Wing01 )
{
shapeFile = "~/data/shapes/ship/wing01.dts";
emap = true;
};

function makeSHAPENAME( %position )
{
%newSHAPENAME = new StaticShape()
{
datablock = Wing01;
position = %position;
};
}

datablock StaticShapeData( Wing02 )
{
shapeFile = "~/data/shapes/ship/wing02.dts";
emap = true;
};
function makeSHAPENAME( %position )
{
%newSHAPENAME = new StaticShape()
{
datablock = Wing02;
position = %position;
};
}


I can move the ship to the start marker by entering playership.setTransform(startMarker.getTransform());
into the console. I'd prefer to have to ship smoothly move to the marker and stop and not change the direction it's facing.

The code for my store gui screen is as follows and contains what I thought would disable the player's control of the ship:

//////////////////////////////////////store1 setup//////////////////////////////

function setupstore1()
{
$store1 = new SimGroup() {};

%scriptobj = new ScriptObject()
{
name = wing1;
count = 3;
cost = 10;
};

$store1.add(%scriptobj);

%scriptobj2 = new ScriptObject()
{
name = wing2;
count = 2;
cost = 21;

};

$store1.add(%scriptobj2);
}

datablock TriggerData( STORE1trigger )
{
tickperiodMS = 1000;
};

function STORE1trigger::onEnterTrigger( %this, %trigger, %obj )
{
nullControl();
$store = $store1;
openstore();
Parent::onEnterTrigger( %this, %trigger, %obj );
}


function STORE1trigger::onLeaveTrigger( %this, %trigger, %obj )
{
if(%obj == $player)
{
exitstore();
}
Parent::onLeaveTrigger( %this, %trigger, %obj );
}


function STORE1trigger::onTickTrigger( %this, %trigger )
{
Parent::onTickTrigger( %this, %trigger );
}

function nullControl()
{
vehicleDriverMap.bind( keyboard, w, null );
vehicleDriverMap.bind( keyboard, a, null );
vehicleDriverMap.bind( keyboard, d, null );
vehicleDriverMap.bind( keyboard, s, null );

vehicleDriverMap.bind( mouse, yaxis, null );
vehicleDriverMap.bind( mouse, xaxis, null );

vehicleDriverMap.bind( keyboard, left, null );
vehicleDriverMap.bind( keyboard, right, null );
vehicleDriverMap.bind( keyboard, up, null );
vehicleDriverMap.bind( keyboard, down, null );
vehicleDriverMap.bind( keyboard, space, null );
}

I'm not too familiar with keybinds yet, but I know the nullControl() function is incorrect since it doesn't work. I'm gonna guess I have to change the binds in the actual vehicleDriverMap.cs file via a global variable?


Thanks for any assistance,
Devin