Let player enter vehicle
by Lorenz Auzinger · in Torque Game Engine · 05/15/2005 (9:34 am) · 11 replies
Hi!
Is it possible to let the player from the FPS Starter Kit enter a vehicle (like Halo)?
Is it possible to let the player from the FPS Starter Kit enter a vehicle (like Halo)?
About the author
#2
And I can't leave the vehicle. If I press the jump key, Armor::doDismount is called, but the player just rotates a bit and stays in the car.
[EDIT]It's working now!
05/16/2005 (1:32 am)
I was able to mount the player to the car from the Racing Starter Kit, but it only worked when I changed WheeledVehicleData::onCollision:function WheeledVehicleData::onCollision(%this,%obj,%col,%vec,%speed)
{
// Collision with other objects, including items
%client = %col.client;
if(!%client)
{
return;
}
%obj.mountObject(%col, 0);
}But why doesn't the default Armor::onCollision work (player.cs)?And I can't leave the vehicle. If I press the jump key, Armor::doDismount is called, but the player just rotates a bit and stays in the car.
[EDIT]It's working now!
#3
07/13/2006 (2:25 am)
Lorenz, I'm happy that you managed to get it working, but could you please provide your fix for others to learn from? I'm trying to do this myself, and would love to know what you did to get it right. Thanks in advance :)
#4
You can use the car.cs file from the racing starter kit.
Add mountPose[0] = "Sitting"; to the WheeledVehicleData datablock.
Add %obj.mountable = true; to the WheeledVehicleData::create function.
Add exec("./car.cs"); to the onServerCreate function in game.cs.
To player.cs add the following:
Of course you need the car model too.
If you have done that, you should be able to use the car in the GameOne sample.
07/13/2006 (4:25 am)
I don't know all the changes I made in May 05 anymore, but I can tell you how you can change the GameOne sample (the tutorial game) to allow the player to drive a car.You can use the car.cs file from the racing starter kit.
Add mountPose[0] = "Sitting"; to the WheeledVehicleData datablock.
Add %obj.mountable = true; to the WheeledVehicleData::create function.
Add exec("./car.cs"); to the onServerCreate function in game.cs.
To player.cs add the following:
function PlayerShape::onMount(%this,%obj,%vehicle,%node)
{
if (%node == 0) {
%obj.setTransform("0 0 0 0 0 1 0");
%obj.setActionThread(%vehicle.getDatablock().mountPose[%node],true,true);
%obj.setControlObject(%vehicle);
%obj.client.setObjectActiveImage(%vehicle, 2);
}
}
function PlayerShape::doDismount(%this, %obj, %forced)
{
// This function is called by player.cc when the jump trigger
// is true while mounted
if (!%obj.isMounted())
return;
// Position above dismount point
%pos = getWords(%obj.getTransform(), 0, 2);
%oldPos = %pos;
%vec[0] = " 0 0 1";
%vec[1] = " 0 0 1";
%vec[2] = " 0 0 -1";
%vec[3] = " 1 0 0";
%vec[4] = "-1 0 0";
%impulseVec = "0 0 0";
%vec[0] = MatrixMulVector( %obj.getTransform(), %vec[0]);
// Make sure the point is valid
%pos = "0 0 0";
%numAttempts = 5;
%success = -1;
for (%i = 0; %i < %numAttempts; %i++) {
%pos = VectorAdd(%oldPos, VectorScale(%vec[%i], 3));
if (%obj.checkDismountPoint(%oldPos, %pos)) {
%success = %i;
%impulseVec = %vec[%i];
break;
}
}
if (%forced && %success == -1)
%pos = %oldPos;
%obj.unmount();
%obj.setControlObject(%obj);
if(%obj.mVehicle)
%obj.mVehicle.mountable = true;
%obj.mountVehicle = false;
%obj.schedule(4000, "mountVehicles", true);
// Position above dismount point
%obj.setTransform(%pos);
%obj.applyImpulse(%pos, VectorScale(%impulseVec, %obj.getDataBlock().mass));
%obj.setPilot(false);
%obj.vehicleTurret = "";
}
function PlayerShape::onCollision(%this,%obj,%col)
{
// Mount vehicles
%this = %col.getDataBlock();
if((%this.className $= WheeledVehicleData || %this.className $= FlyingVehicleData
|| %this.className $= HoverVehicleData) && %obj.mountVehicle
&& %obj.getState() $= "Move")
{
if(%col.mountable)
{
%node = 0;
%col.mountable = false;
%col.mountObject(%obj,%node);
%obj.mVehicle = %col;
}
}
}
function Player::mountVehicles(%this,%bool)
{
// If set to false, this variable disables vehicle mounting.
%this.mountVehicle = %bool;
}Add %obj.mountVehicle = true; to the PlayerShape::onAdd function.Of course you need the car model too.
If you have done that, you should be able to use the car in the GameOne sample.
#5
I'll let you know how I go...
Dan
07/16/2006 (6:30 pm)
Hey thanks man... I appreciate you taking the time to paste your code, unfortunately, I'm doing SOMETHING wrong, I can't seem to get it working. :(I'll let you know how I go...
Dan
#6
To me, it is essential to have as a base template the ability to mount/unmount vehicles, as well as activate certain things with a key bind, access an inventory, etc.. I can hardly believe that NOBODY has thought to make a Driving/shooting/interracting starter kit. Think UT04 for example. Variety is the spice of life, after all.
Just a few thoughts/frustrations. by the way, I am in serious need of sleep, so please excuse my drivel.
kaff
08/09/2006 (10:41 pm)
Okay, I still have had zero success with mounting a vehicle. I've tried several different approaches now, following instructions (as far as I can tell) to the letter, and still cannot enter a vehicle. Also, I moved the starter.racing\server\scripts\car.cs and \starter.racing\data\shapes\buggy folders into the tutorial.base dir but nothing works - it's loaded as a static shape - I tried to exec car.cs in (can't remember which file I should edit!?) - anyway, wherever I'm supposed to exec car.cs I did and no worky. I'm an artist, not a coder, so I'm a bit of a virgin here... I'm not slow tho, I can do stuff when I'm shown WHY I'm editing files, but I do find I get swamped by the sheer number of files and folders needing to be edited just so I can add a buggy shape to the game. To me, it is essential to have as a base template the ability to mount/unmount vehicles, as well as activate certain things with a key bind, access an inventory, etc.. I can hardly believe that NOBODY has thought to make a Driving/shooting/interracting starter kit. Think UT04 for example. Variety is the spice of life, after all.
Just a few thoughts/frustrations. by the way, I am in serious need of sleep, so please excuse my drivel.
kaff
#7
Open the editor when in the game.
ascertain the id number for the car.
use that number to dump the cars properties to the console.
take note in these properties there is a bool called mountable or something like that.
if this is set to 0 you will not be able to enter the vehicle.
when using the editor I believe you can select the car find the mountable property and set it to 1
you can also use the console.
so yea, this is how you dump object properties in the game.
if you put that to use you can pick up on how the script is finding and making use of these "tag" variables.
armed with that information you should be able to solve this no trouble.
there are lots of tutorials on this and script code too.
I did a vehicle tutorial a long time ago that has been superceded by many others.
but if you dig it up it has the script code you need to fix this.
and maybe reading the tutorial and seeing the trouble other people had and the fix's that might help as well.
08/10/2006 (12:13 am)
Dan:Open the editor when in the game.
ascertain the id number for the car.
use that number to dump the cars properties to the console.
1401.dump();
take note in these properties there is a bool called mountable or something like that.
if this is set to 0 you will not be able to enter the vehicle.
when using the editor I believe you can select the car find the mountable property and set it to 1
you can also use the console.
1401.mountable=1;
so yea, this is how you dump object properties in the game.
if you put that to use you can pick up on how the script is finding and making use of these "tag" variables.
armed with that information you should be able to solve this no trouble.
there are lots of tutorials on this and script code too.
I did a vehicle tutorial a long time ago that has been superceded by many others.
but if you dig it up it has the script code you need to fix this.
and maybe reading the tutorial and seeing the trouble other people had and the fix's that might help as well.
#8
08/12/2006 (10:14 pm)
Thanks Badguy - I'll give it a shot. If this works, I'll only have another gazillion problems to solve :D
#9
10/27/2007 (6:16 am)
Thanks man =) you fixed my "vehicle won't mount problem" mountable was missing
#10
Thanks for the info!
Unfortunately, I wasn't able to get this to work until I put the %obj.mountable = true; in the WheeledVehicleData::onAdd function. In the WheeledVehicle::create function, it does nothing. This is using TGE 1.5.2.
01/20/2008 (5:02 pm)
Hi,Thanks for the info!
Unfortunately, I wasn't able to get this to work until I put the %obj.mountable = true; in the WheeledVehicleData::onAdd function. In the WheeledVehicle::create function, it does nothing. This is using TGE 1.5.2.
#11
What .cs file is the PlayerShape::onAdd function in?
I've opened every script that I could think of, and done a search with the FIND command with no results each time.
**Edit** It DOES work if I do the dump to console, then mount. Just curious about the .cs file for future vehicle reference.
**Edit #2** Noticed a neat little bug. Run over an AIPlayer and it comes along for the ride too. lol.
That could be a good thing...or a baaaaaaaaaaad thing.
03/22/2008 (9:53 pm)
Pardon my stupidity /frown.What .cs file is the PlayerShape::onAdd function in?
I've opened every script that I could think of, and done a search with the FIND command with no results each time.
**Edit** It DOES work if I do the dump to console, then mount. Just curious about the .cs file for future vehicle reference.
**Edit #2** Noticed a neat little bug. Run over an AIPlayer and it comes along for the ride too. lol.
That could be a good thing...or a baaaaaaaaaaad thing.
Torque Owner Vashner
mount player