Game Development Community

Vehicle won't move

by Sam Contapay · in Torque Game Engine · 01/06/2005 (9:05 pm) · 14 replies

I scrapped most of the example code so I can start from a fresh base. i got the engine up and running and a hover tank model in the game, but for some reason the tank won't move. It is created using a HoverVehicle datablock and it shows up in game, I replaced a player avatar I had before with this block.

I then created the move accelerate function as in the example starter.racing but when I hit "w" which I mapped to the accelerate function the hover tank just sits there. I created this from scratch so I wonder if there is something I have to call so the game knows to update the vehicle's position or to have it work properly so that it can accelerate?

Thanks.

#1
01/06/2005 (10:44 pm)
Paste your Datablock here...
#2
01/07/2005 (6:56 am)
Here is the hovertank.cs file I have

datablock HoverVehicleData(DefaultTank)
{
   category = "Vehicles";
   shapeFile = "~/data/models/players/player.dts";
   emap = true;

   maxDamage = 1.0;
   destroyedLevel = 0.5;

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

   // Rigid Body
   mass = 200;
   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 = 10000;       // Engine power
   engineBrake = 600;         // Braking when throttle is 0
   brakeTorque = 8000;        // When brakes are applied
   maxWheelSpeed = 30;        // Engine scale by current speed / max speed

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

// Copied below from a GG post, get the original author name and add here for credit
// whenever I have a chance or if this code is going to stay in here. Added mostly for troubleshooting
dragForce = 0.7; //* constant drag force, slows more when not thrusting
vertFactor = 0.7; //* 0-1 applys higher drag when "airborne"
floatingThrustFactor = 0.5; //* if the hover is "airborne" (meaning it is higher above terrain then
// the stabLenMax) multiply thrustforce by this to determine how much thrust
// to allow

floatingGravMag = 2.5; //* higher numbers cuts out air time, keeping the vehicle very close to the terrain

maxThrustSpeed = 140 / 1.67;//*
mainThrustForce = 70; //* normal forward force
reverseThrustForce = 60; //*
strafeThrustForce = 20; //*
turboFactor = 1.4; //*
//*
brakingForce = 75; //* the force applied for brakes
brakingActivationSpeed = 4; //* the speed at which automatic breaking is applied
//*
stabLenMin = 4; //* hovers basically ride on a spring, which during normal movement keeps the vehicle within
stabLenMax = 5.5; //* the following values distance from the ground

stabSpringConstant = 300; //* higher values provide for less bobbles from bumps and direction changes

stabDampingConstant = 200; //* higher values quickly smooths out residual up and down motion from landings and bumps

gyroDrag = 30; //* determines turning rate of vehicle lower values provide for quick turn responce, but are less
//* normalized and hard to control. lower numbers also decrease the effect of the direction the car is
//* facing upon its actual direction of momentum.

normalForce = 30; //* normalizes the vehicles roll and pitch with respect to the terrain. High numbers provide
//* a stable smooth positioning. Low numbers allow more roll and pitch and increases terrain collisions

restorativeForce = 20; //* how fast the vehicle will be restored to paralell over the terrain; higher is faster

steeringForce = 100; //* the rate of turn for the vehicle, higher is faster

rollForce = 20; //* this makes rolling/banking (turning) more responsive (higher numbers reduces the ability
//* to turn 180 degrees without changing the direction of momentum.

pitchForce = 20; //* higher numbers gives more force and movement for pitching the nose up/down

};
#3
01/07/2005 (6:57 am)
Have to split

function DefaultTank::create(%block)
{
   %obj = new HoverVehicle() {
	dataBlock = %block;
   };

   return(%obj);
}

function DefaultTank::onAdd(%this,%obj)
{
// Init code for the tank
%obj.setEnergyLevel(%this.MaxEnergy);
%obj.setRechargeRate(%this.rechargeRate);
}

function DefaultTank::onCollision(%this,%obj,%col,%vec,%speed)
{
// Collision with other objects including crap and items, terrain is automatic
}

And here is my movement code defined in the client section

$movementSpeed = 1; // m/s

function setSpeed(%speed)
{
   if(%speed)
      $movementSpeed = %speed;
}

function moveleft(%val)
{
   $mvLeftAction = %val * $movementSpeed;
}

function moveright(%val)
{
   $mvRightAction = %val * $movementSpeed;
}

function moveup(%val)
{
   $mvUpAction = %val * $movementSpeed;
}

function movedown(%val)
{
   $mvDownAction = %val * $movementSpeed;
}

function accelerate(%val)
{
   $mvForwardAction = %val * $movementSpeed;
}

function brake(%val)
{
   $mvBackwardAction = %val * $movementSpeed;
}

function turnLeft( %val )
{
   $mvYawRightSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
}

function turnRight( %val )
{
   $mvYawLeftSpeed = %val ? $Pref::Input::KeyboardTurnSpeed : 0;
}

function yaw(%val)
{
   $mvYaw += getMouseAdjustAmount(%val);
}

function pitch(%val)
{
   $mvPitch += getMouseAdjustAmount(%val);
}

function getMouseAdjustAmount(%val)
{
   // based on a default camera fov of 90'
   return(%val * ($cameraFov / 90) * 0.01);
}

playerKeymap.Bind(keyboard, "w", accelerate);
playerKeymap.Bind(keyboard, up, moveup);
playerKeymap.Bind(keyboard, down, BackUp);
playerKeymap.Bind(keyboard, a, turnLeft);
playerKeymap.Bind(keyboard, d, turnRight);
#4
01/07/2005 (6:58 am)
This is mostly ripped from the examples, but I didn't want every file that was defined in the examples in this simple game I am making, and the "book" and it works well if I replace my movment code for normal character control and replace the vehicle with a player avatar. There is no player avatar as the vehicle is the player their is no mounting or dismounting.

The tank shows it drops upon mission load hits the ground and shakes around. So thats good, but when I hit "w" on my keyboard to move forward it just sits there.

TIA for any help.
#5
01/07/2005 (7:10 am)
What is the code that actually creates the tank object and assigns it to the client (player)? In stock, it's normally done in starter.racing/server/scripts/game.cs, function GameConnection::onClientEnterGame(), which then calls spawnCar, which calls createCar. createCar is what I'd like to see first, hehe.
#6
01/07/2005 (8:36 am)
Is there any console errors? Did you checkout console.log?
#7
01/07/2005 (6:43 pm)
Just a stupid idea : Try using the buggy DTS instead of the player DTS.

BTW, I don't know why, but hover vehicles are harder to create than flying vehicles. The datablocks values seem to be trickier and one of the hover tank resources didn't really work for me.
#8
01/07/2005 (6:45 pm)
@Bruno: that's part of why I wanted to see his createCar code--I think he may be using the wrong datablock, or execution chain.
#9
01/07/2005 (6:45 pm)
@Dennis: nope no console erros

@Stephen: you can find the code below

@Anyone and all posters thanks for any help! :) The tank does spawn but it just sits there and doesn't move

function GameConnection::OnClientEnterGame(%this)
//----------------------------------------------------------------------------
// Called when the client has been accepted into the game by the server.
//----------------------------------------------------------------------------
{
   // Create a player object.
   %this.spawnTank();
}

function GameConnection::spawnTank(%this)
{
  // Create tank object
  %this.createTank("0 0 220 1 0 0 0");
}

function GameConnection::createTank(%this, %spawnPoint)
{
  if (%this.tank > 0) {
	error("Attempting to create an angus ghost!");
  }

  // Create the tank
  %tank = new HoverVehicle() {
	dataBlock = DefaultTank;
	client = %this;
  };

  // Player setup
  %tank.setTransform(%spawnPoint);
  %tank.setShapeName(%this.name);
  
  // Give client control of object
  %this.tank = %tank;
  %this.setControlObject(%tank);

  // Toggle to 3rd person point of view as that is how this game will be played
  $firstperson = false;
}
#10
01/07/2005 (6:53 pm)
Where exactly (what file) are your moveMap binds for your keys?

Default TGE expects to look first in default.binds.cs, but it also will check for config.cs (later), and over-write anything that exists in default.binds.cs (it actually deletes any previous moveMaps).

Try seeing if you have a config.cs, and if so, either copy the moveMaps there, or simply rename the file (and delete the config.dso) and see what happens.

EDIT: A secondary way to test this first is to see if your arrow keys still accelerate the tank.
#11
01/07/2005 (6:56 pm)
Are you sure you use playerKeymap in playGui.cs? -> the same as for the character which works
#12
01/07/2005 (9:05 pm)
@All: First I'm very thankful for all the help everyone is trying to give. It is totally awesome the amount of feedback and response I'm getting and it makes me feel good to know that this community is so helpful.

My keymaps are defined in the player.cs file. This is something I did as a hold over from writing the game from scratch. I basically just took the default game files and removed what I don't need now, sort of a learning expierence. I know that the keybinds are accepted, I don't know if this is a good way to tell, because the global keymaps are still being accepted like the escape key and console, which I have defined there in that area.

When I drop in my old file which had a player avatar it works fine, but when I drop in the vehicle datablock it doesn't work. Thats why I was wondering if there is a special way to use vehicles in code, like call a special function so it knows to update. As I have above I have a SetSpeed function call, but I don't see anywhere in the script where that is called. I've also tried printing to screen when I hit a key and that works I see what I wanted printed to screen on there. There is probably something else I am missing but I can't see it. Does the vehicle update itself automatically? There is no special initialization code I have to call to let it know that it is a vehicle it now has to process?

If anyone would like I can send the script files I am using in an email so you can see what I am doing. I can't send the DTS shape I bought it off turbo squid so there maybe some copyright restrictions but anyone who is willing to post an email address I would be happy to send the zip file of what scripts I have now. You can replace it with a default DTS shape for the tank I'm using.
#13
01/07/2005 (9:08 pm)
Do check to see if you have a config.cs in your client area, and see if the keymaps made it into that file. While it doesn't sound like this is your most probable issue, it's certainly something easy to check, and I know that the config.cs gets generated -somewhere- in the code that I haven't found myself yet.
#14
01/07/2005 (11:19 pm)
Actually I solved the problem!!! We'll not solved but fixed. I don't know what exactly fixed the problem but the solution was from the new datablock I got below and once more it was found in the resource search on this site, so it wasn't me :) But here's the new datablock. But I just wanted everyone to know thanks for the help and I couldn't look in config.cs or default.bind.cs because what I am creating doesn't use any of the example code you see in any of the starter packages I just started making it from scratch and from the "book" by Mr Finney.

Here's the datablock soemthing in this new one as compared to the one at top made the tank actually move - go figure. If anyone can point it out please let me know for future reference.

datablock HoverVehicleData(DefaultTank)
{
   category = "Vehicles";
   shapeFile = "~/data/models/players/player.dts";
   emap = true;

   className = HoverTank;
   maxDamage = 1.0;
   destroyedLevel = 0.5;

   //floatingGravMag = 55.5;
   maxDamage = 1000.0;
   destroyedLevel = 900.0;

   drag = 0.2;
   density = 0.3;

   integration = 4;           // Physics integration: TickSec/Rate
   collisionTol = 0.3;        // Collision distance tolerance
   contactTol = 0.2;          // Contact velocity tolerance

   cameraMaxDist = 30.0;
   cameraOffset = 15.5;
   // cameraLag = 0.1;

   rechargeRate = 0.7;
   energyPerDamagePoint = 75;
   maxEnergy = 650;
   minJetEnergy = 165;
   jetEnergyDrain = 1.3;

// Rigid Body
   mass = 105;
   bodyFriction = 0.1;
   bodyRestitution = 0.3;
   softImpactSpeed = 20; // Play SoftImpact Sound
   hardImpactSpeed = 28; // Play HardImpact Sound

// Ground Impact Damage (uses DamageType::Ground)
   minImpactSpeed = 29;
   speedDamageScale = 0.10;

// Object Impact Damage (uses DamageType::Impact)
   collDamageThresholdVel = 23;
   collDamageMultiplier = 0.030;

   dragForce = 1.0;
   // dragForce = 25 / 45.0;
   vertFactor = 0.8;
   floatingThrustFactor = 0.5;

   mainThrustForce = 750;
   reverseThrustForce = 600;
   strafeThrustForce = 670;
   turboFactor = 1.5;

   brakingForce = 900;
   brakingActivationSpeed = 30;

   stabLenMin = 28.50;
   stabLenMax = 32.50;
   stabSpringConstant = 38;
   stabDampingConstant = 28;

   gyroDrag = 18; // 16
   //gyroForce = 50;
   normalForce = 30;
   restorativeForce = 1600;
   steeringForce = 1000;
   rollForce = 30;
   pitchForce = 30;

};

EDIT: FYI it was Tom Feni that sumbitted that resource. You can view it here.