Spawn player INSIDE spawned vehicle?
by John Vanderbeck · in Torque Game Engine · 03/01/2004 (7:03 am) · 17 replies
What I need to do is spawn both a player and a vehicle, but I need the player to spawn already mounted to the vehicle. IE I can't spawn the vehicle and the player and let the player mount the vehicle on his own (Though if I can manage a way to script that that would be even better than our current approach).
In our game, there is no serperate play on foot. All gameplay takes place in vehicles. However we still want a biped player mounted to the vehicles for open air vehicles and transparent cockpit ones. IE we still want the player and vehicle as seperate entities, but we don't want them running around outside thier vehicles. So we either need to spawn them already mounted with thier chosen vehicle, or spawn them next to the vehicle and have a scripted mounting of the vehicle that they have no control over.
Any tips?
In our game, there is no serperate play on foot. All gameplay takes place in vehicles. However we still want a biped player mounted to the vehicles for open air vehicles and transparent cockpit ones. IE we still want the player and vehicle as seperate entities, but we don't want them running around outside thier vehicles. So we either need to spawn them already mounted with thier chosen vehicle, or spawn them next to the vehicle and have a scripted mounting of the vehicle that they have no control over.
Any tips?
#2
03/01/2004 (12:26 pm)
Thanks, I guess I didin't expect it to be so simple :p Might look funny, but I won't know until I try it.
#3
If not, well... you can probably live with it looking a bit off and move on to the rest of your game. ;)
03/01/2004 (8:43 pm)
It should be pretty smooth... the events should all propagate to the clients in one tick.If not, well... you can probably live with it looking a bit off and move on to the rest of your game. ;)
#4
I have never seen a "delay" on the client side spawning a vehicle and have the client see the wheels at not beling there and then suddenly they show up.
Same concept, just not treating the "person" as the primary shape which makes sense because you don't want them walking around outside their vehicle.
Although if Ben's idea works (and I think it would) it might be a better solution. It would leave open the door for you to have your players walk around outside, if your game design went that way.
03/02/2004 (4:46 am)
Maybe you could turn the tables around and make the vehicle your player (like the racing demo) and your "person" as just a shape. In the onSpawn for the vehicle mount the "person" the way you would mount wheels, guns or turrets.I have never seen a "delay" on the client side spawning a vehicle and have the client see the wheels at not beling there and then suddenly they show up.
Same concept, just not treating the "person" as the primary shape which makes sense because you don't want them walking around outside their vehicle.
Although if Ben's idea works (and I think it would) it might be a better solution. It would leave open the door for you to have your players walk around outside, if your game design went that way.
#5
Hey, I'm trying to do the samething you are doing. Have you had any luck? If you have is there anyway you could pass some pointers along. Right now I'm creating both the player and the vehicle in the "starter.racing/server/scripts/game.cs" file. I'm doing it right now and don't know if its going to work yet. Then I'm going to try to mount the player to the vehicle in the same file. Is this close to being correct? Any help would be great! I've added the GuiVehicleHealthBar.cc to "engine/game/vehicles/" folder so the car can take some damage. Thanks to Anthony Rosenbaum for that resource.
08/24/2004 (9:15 pm)
John Vanderbeck or Anyone,Hey, I'm trying to do the samething you are doing. Have you had any luck? If you have is there anyway you could pass some pointers along. Right now I'm creating both the player and the vehicle in the "starter.racing/server/scripts/game.cs" file. I'm doing it right now and don't know if its going to work yet. Then I'm going to try to mount the player to the vehicle in the same file. Is this close to being correct? Any help would be great! I've added the GuiVehicleHealthBar.cc to "engine/game/vehicles/" folder so the car can take some damage. Thanks to Anthony Rosenbaum for that resource.
#6
08/28/2004 (11:17 am)
Sounds like a generally good approach.
#7
Spawn the player, spawn the car, in the function(may not be the right name) "vehicle::onNewDatablock()" mount the player to the car. Should happen so fast nobody ever see's that it didn't happen instantly.
John, instead of making your player models into players, just make them images instead using "datablock shapeBaseImageData()", spawn your players as vehicles like in the racing demo and then mount the player image to to the mount node. If you aren't going to have them run around, then there is no point to making a fully blown ready to play player model for this. Dont even bother with animations or any of that. If you want a little more realism to it, then what I would dois build my model in a sitting position, animate the head and the mountpoint separately from the entire body allowing it to rotate 90 degree's both ways(left/right) and then make your vehicle's mountpoint rotate when the player looks left or right. This will cause the head on your player to turn left and right when the mount node turns.
08/28/2004 (12:39 pm)
What's the problem here?Spawn the player, spawn the car, in the function(may not be the right name) "vehicle::onNewDatablock()" mount the player to the car. Should happen so fast nobody ever see's that it didn't happen instantly.
Quote:All gameplay takes place in vehicles. However we still want a biped player mounted to the vehicles for open air vehicles and transparent cockpit ones.
John, instead of making your player models into players, just make them images instead using "datablock shapeBaseImageData()", spawn your players as vehicles like in the racing demo and then mount the player image to to the mount node. If you aren't going to have them run around, then there is no point to making a fully blown ready to play player model for this. Dont even bother with animations or any of that. If you want a little more realism to it, then what I would dois build my model in a sitting position, animate the head and the mountpoint separately from the entire body allowing it to rotate 90 degree's both ways(left/right) and then make your vehicle's mountpoint rotate when the player looks left or right. This will cause the head on your player to turn left and right when the mount node turns.
#8
here is the code: the error messages are just for debugging purposes
function GameConnection::createCar(%this, %spawnPoint)
{
error("inside onNewDataBlock");
if (%this.car > 0) {
// The client should not have a player currently
// assigned. Assigning a new one could result in
// a player ghost.
error( "Attempting to create an angus ghost!" );
}
%player = new Player()
{
dataBlock = PlayerBody;
client = %this;
};
error("created player");
MissionCleanup.add(%player);
error("added driver to missionCleanup");
// player setup
%player.setTransform(%spawnPoint);
%player.setShapeName(%this.name);
%this.camera.setTransform(%player.getEyeTransform());
%this.player = %player;
//%this.setControlObject(%player);
// Create the car object
%car = new WheeledVehicle() {
dataBlock = DefaultCar;
mountable = true;
client = %this;
};
error("created car");
MissionCleanup.add(%car);
error("added car to missionCleanup");
//attempt to mount player
error("Attempting to mount player to vehicle");
%node = "mount0";
//%this.player.onMount(%this,%player,%car,%node);
%car.mountObject(%player, %node);
//%player.Armor.onMount(%this,%player,%car,%node);
// Player setup...
%car.setTransform(%spawnPoint);
%car.setShapeName(%this.name);
// Update the camera to start with the player
%this.camera.setTransform(%car.getEyeTransform());
// Give the client control of the player
%this.car = %car;
%this.setControlObject(%car);
error("leaving racing.game.cs");
}
09/01/2004 (12:54 pm)
Ok... I got the player and the vehicle spawning but the player is not mounting to the vehicle. In the starter.racing/server/scripts/racing.game.cs after i create the car and add it to the mission clean up i've tried %car.mountObject(%player,%node); which %node = "mount0" the mount point I created in the car model and named mount0. I've tried vehicle::mountObject(%player, %node); i've tried %player.onMount(%this,%player,%car,%node); and %this.player.onMount(%this,%player,%car,%node); the player always ends up standing next to the vehicle. I have the controlOject set to the vehicle considering all i'm using the player for is to be able to pick up objects, take damage, etc... i'm continuing to work on it and hopefully get the player to mount to the vehicle and will post if I get it done. Thanks for the help ahead of time!!!here is the code: the error messages are just for debugging purposes
function GameConnection::createCar(%this, %spawnPoint)
{
error("inside onNewDataBlock");
if (%this.car > 0) {
// The client should not have a player currently
// assigned. Assigning a new one could result in
// a player ghost.
error( "Attempting to create an angus ghost!" );
}
%player = new Player()
{
dataBlock = PlayerBody;
client = %this;
};
error("created player");
MissionCleanup.add(%player);
error("added driver to missionCleanup");
// player setup
%player.setTransform(%spawnPoint);
%player.setShapeName(%this.name);
%this.camera.setTransform(%player.getEyeTransform());
%this.player = %player;
//%this.setControlObject(%player);
// Create the car object
%car = new WheeledVehicle() {
dataBlock = DefaultCar;
mountable = true;
client = %this;
};
error("created car");
MissionCleanup.add(%car);
error("added car to missionCleanup");
//attempt to mount player
error("Attempting to mount player to vehicle");
%node = "mount0";
//%this.player.onMount(%this,%player,%car,%node);
%car.mountObject(%player, %node);
//%player.Armor.onMount(%this,%player,%car,%node);
// Player setup...
%car.setTransform(%spawnPoint);
%car.setShapeName(%this.name);
// Update the camera to start with the player
%this.camera.setTransform(%car.getEyeTransform());
// Give the client control of the player
%this.car = %car;
%this.setControlObject(%car);
error("leaving racing.game.cs");
}
#10
09/01/2004 (1:00 pm)
Man that was fast!!!! I'll give it a try and let you know! Thanks!
#11
Did i mention how much i love this forum!!!
09/01/2004 (1:04 pm)
Well this is definitely the world record of a post that fixed the problem in exactly 1 minute after I posted! Well it works and I thank all who helped for the help!Did i mention how much i love this forum!!!
#12
12/02/2005 (12:16 pm)
I love it so much too!!! great people here : )
#13
12/02/2005 (12:21 pm)
I'd love to see this as a resource.. My ork would be delighted to get an orkbuggy drive arround :)
#14
That is in game.cs.
Is that the correct way to mount the car to the player?
02/01/2007 (11:20 pm)
Trying to do a simple mount of the car from starter.racing onto the player from starter.fps. Added car.cs and exec'd it. I'm getting this error in my console log, not sure if i'm doing it right.%car = new WheeledVehicle() {
dataBlock = DefaultCar;
mountable = true;
client = %this;
};%player.mountObject(%car,0);
That is in game.cs.
Is that the correct way to mount the car to the player?
#15
02/02/2007 (2:31 am)
I think you want to go about it the other way and mount the player to the car.
#16
02/04/2007 (12:51 pm)
Couldnt you just create the player so it drops into the shape on load, and then delete the unmount function. Sure the player would see some movement, but you could have it look like they are mounting the vehicle. and if the button to unmount is disable then they cant run around, but you still get a mounted vehicle, with seperate model.
#17
02/04/2007 (2:41 pm)
Got it working from Anthony's sug. Forgot to post. Thanks.
Associate Kyle Carter