Replacing Default Object
by K · in Technical Issues · 02/12/2008 (5:35 pm) · 15 replies
How do I replace the default player object (avatar, I think it's referred to as) with a custom model? Every time I try (by editing the player.cs file) I end up in the middle of the terrain looking at nothing. All I do is edit the player.cs file with custom data blocks, but it doesn't quite work.
#2
02/12/2008 (7:07 pm)
Worked well, the only problem being I loaded in a jet model, so if I just use a FlyingVehicle Dateblock it should work?
#3
02/12/2008 (9:39 pm)
It should work properly, although the jet is a vehicle and vehicle scripts are different than player scripts. If you know a decent amount of vehicle scripting, you should be able to do it.
#4
02/13/2008 (12:29 pm)
That's the problem, I'm just messing around with the demo, and I don't know much about TorqueScript right now. If there was a tutorial on making a complete game, that would help a lot. I'll look into the ones on Code Sampler and see if they do the trick.
#5
02/14/2008 (10:44 pm)
I was looking around on TDN (Torque Developer Network) and found a resource about flying vehicles. Here's the link, tdn.garagegames.com/wiki/DTS/3dsmax/Creating_a_Simple_Flying_Vehicle If you didn't purchase Torque, I don't think you can have access to TDN. Tell me if you don't have access, and i'll post the code here.
#6
02/15/2008 (8:39 am)
Ok, thanks. I do have somewhat restricted access to TDN (I can't access some pages), but I can see this one. Thanks for pointing that out. The part where it originally screwed up for me is in server/game.cs, when it comes to spawning the player. I'll just keep trying.
#7
If you're still having problems, open the folder called "data" and then open "shapes". Make a new folder called "vehicles" and put your jet model in it. Then rename the model so it's called TKFighter.dts. You want to do that because in the vehicle scripts it says
02/15/2008 (12:00 pm)
I think I know what the problem is. Open game.cs and look for dataBlock = PlayerBody;It is somewhere around line 377. Replace PlayerBody with TKFighter so it should look like this
dataBlock = TKFighter;The flying vehicle is called "TKFighter" and the default player is called "PlayerBody". Now you should spawn as a vehicle.
If you're still having problems, open the folder called "data" and then open "shapes". Make a new folder called "vehicles" and put your jet model in it. Then rename the model so it's called TKFighter.dts. You want to do that because in the vehicle scripts it says
shapeFile = "~/data/shapes/vehicles/tkfighter.dts"; // Shape FileAnd that's where the jet model must be located or else the model wouldn't load. That should do the trick but i'll try to find the problem if it doesn't work.
#8
Object 'PlayerShape' is not a member of the 'GameBaseData' data block class
tutorial.base/server/game.cs (99): Register object failed for object (null) of class Player.
Set::add: Object "0" doesn't exist
tutorial.base/server/game.cs (103): Unable to find object: '0' attempting to call function 'setTransform'
tutorial.base/server/game.cs (104): Unable to find object: '0' attempting to call function 'setShapeName'
tutorial.base/server/game.cs (107): Unable to find object: '0' attempting to call function 'getEyeTransform'
Here's the code for game.cs
I'm not sure what else I have to change to get it to work.
02/21/2008 (7:32 am)
Still haven't been able to figure it out, but slowly getting closer. I used the tutorial.base off Code Sampler and have been able to replace the green guy with my model. Now, when I try to replace player.cs with jet.cs, I get the errors:Object 'PlayerShape' is not a member of the 'GameBaseData' data block class
tutorial.base/server/game.cs (99): Register object failed for object (null) of class Player.
Set::add: Object "0" doesn't exist
tutorial.base/server/game.cs (103): Unable to find object: '0' attempting to call function 'setTransform'
tutorial.base/server/game.cs (104): Unable to find object: '0' attempting to call function 'setShapeName'
tutorial.base/server/game.cs (107): Unable to find object: '0' attempting to call function 'getEyeTransform'
Here's the code for game.cs
//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Server and mission initialization
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function onServerCreated()
{
// This function is called when a server is constructed.
// Master server information for multiplayer games
$Server::GameType = "Torque TTB";
$Server::MissionType = "None";
// Load up all datablocks, objects etc.
exec("./audioProfiles.cs");
exec("./camera.cs");
exec("./editor.cs");
exec("./jet.cs");
}
function onServerDestroyed()
{
// This function is called as part of a server shutdown.
}
//-----------------------------------------------------------------------------
function onMissionLoaded()
{
// Called by loadMission() once the mission is finished loading.
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think();
}
function onMissionEnded()
{
// Called by endMission(), right before the mission is destroyed
AIManager.delete();
}
//-----------------------------------------------------------------------------
// Dealing with client connections
// These methods are extensions to the GameConnection class. Extending
// GameConnection make is easier to deal with some of this functionality,
// but these could also be implemented as stand-alone functions.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function GameConnection::onClientEnterGame(%this)
{
// Every client get's a camera object.
%this.camera = new Camera() {
dataBlock = Observer;
};
MissionCleanup.add( %this.camera );
%this.camera.scopeToClient(%this);
// Create a player object.
%spawnPoint = pickSpawnPoint();
%this.createPlayer(%spawnPoint);
}
function GameConnection::onClientLeaveGame(%this)
{
if (isObject(%this.camera))
%this.camera.delete();
if (isObject(%this.player))
%this.player.delete();
}
//-----------------------------------------------------------------------------
function GameConnection::createPlayer(%this, %spawnPoint)
{
if (%this.player > 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!" );
}
// Create the player object
%player = new Player() {
dataBlock = FlyingVehicleData;
client = %this;
};
MissionCleanup.add(%player);
// Player setup...
%player.setTransform(%spawnPoint);
%player.setShapeName(%this.name);
// Update the camera to start with the player
%this.camera.setTransform(%player.getEyeTransform());
// Give the client control of the player
%this.player = %player;
%this.setControlObject(%player);
}
//-----------------------------------------------------------------------------
function pickSpawnPoint()
{
// Pick the first object in drop point group and use it's
// location as a spawn point.
%group = nameToID("MissionGroup/PlayerDropPoints");
if (%group != -1 && %group.getCount() != 0)
return %group.getObject(0).getTransform();
// If no object was found, return a point near the center of the world
error("Missing spawn point object and/or mission group " @ %groupName);
return "0 0 300 1 0 0 0";
}I'm not sure what else I have to change to get it to work.
#9
If this still doesn't work, open your mission, and open the console (by pressing ~ at the top left below Esc)
and type in
02/21/2008 (3:45 pm)
Try this and the mistake is in bold.//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Server and mission initialization
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function onServerCreated()
{
// This function is called when a server is constructed.
// Master server information for multiplayer games
$Server::GameType = "Torque TTB";
$Server::MissionType = "None";
// Load up all datablocks, objects etc.
exec("./audioProfiles.cs");
exec("./camera.cs");
exec("./editor.cs");
exec("./jet.cs");
}
function onServerDestroyed()
{
// This function is called as part of a server shutdown.
}
//-----------------------------------------------------------------------------
function onMissionLoaded()
{
// Called by loadMission() once the mission is finished loading.
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think();
}
function onMissionEnded()
{
// Called by endMission(), right before the mission is destroyed
AIManager.delete();
}
//-----------------------------------------------------------------------------
// Dealing with client connections
// These methods are extensions to the GameConnection class. Extending
// GameConnection make is easier to deal with some of this functionality,
// but these could also be implemented as stand-alone functions.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function GameConnection::onClientEnterGame(%this)
{
// Every client get's a camera object.
%this.camera = new Camera() {
dataBlock = Observer;
};
MissionCleanup.add( %this.camera );
%this.camera.scopeToClient(%this);
// Create a player object.
%spawnPoint = pickSpawnPoint();
%this.createPlayer(%spawnPoint);
}
function GameConnection::onClientLeaveGame(%this)
{
if (isObject(%this.camera))
%this.camera.delete();
if (isObject(%this.player))
%this.player.delete();
}
//-----------------------------------------------------------------------------
function GameConnection::createPlayer(%this, %spawnPoint)
{
if (%this.player > 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!" );
}
// Create the player object
%player = new Player(player) {
[b]dataBlock = TKFighter;[/b]
client = %this;
};
MissionCleanup.add(%player);
// Player setup...
%player.setTransform(%spawnPoint);
%player.setShapeName(%this.name);
// Update the camera to start with the player
%this.camera.setTransform(%player.getEyeTransform());
// Give the client control of the player
%this.player = %player;
%this.setControlObject(%player);
}
//-----------------------------------------------------------------------------
function pickSpawnPoint()
{
// Pick the first object in drop point group and use it's
// location as a spawn point.
%group = nameToID("MissionGroup/PlayerDropPoints");
if (%group != -1 && %group.getCount() != 0)
return %group.getObject(0).getTransform();
// If no object was found, return a point near the center of the world
error("Missing spawn point object and/or mission group " @ %groupName);
return "0 0 300 1 0 0 0";
}If this still doesn't work, open your mission, and open the console (by pressing ~ at the top left below Esc)
and type in
player.setDatablock(TKFighter);See how that goes.
#10
If it helps at all here's the code for both jet.cs and game.cs
jet.cs
02/22/2008 (8:59 pm)
Same thing, just freezes on "Loading Objects" when trying to load the test mission.If it helps at all here's the code for both jet.cs and game.cs
jet.cs
datablock FlyingVehicleData(Jet)
{
spawnOffset = "0 0 2";
emap = true;
category = "Vehicles";
shapeFile = "~/data/shapes/player/jet.dts"; // Shape File
multipassenger = false;
computeCRC = true;
drag = 0.25;
density = 1.0;
// Mounting Details
numMountPoints = 1;
maxMountSpeed = 0.1;
mountDelay = 8;
dismountDelay = 1;
stationaryThreshold = 0.5;
maxDismountSpeed = 0.1;
mountPose[0] = "Sitting";
mountPointTransform[0] = "0 0 0 0 0 1 0";
isProtectedMountPoint[0] = false;
minMountDist = 2;
// Camera Settings
cameraOffset = 1.5; // Vertical offset from camera mount point
cameraMaxDist = 16;
cameraOffset = 3.65;
cameraLag = 0.1;
cameraRoll = true; // Roll the camera with the vehicle
// Explosions = FighterVehicleExplosion; // Particle Data?
explosionDamage = 10.5;
explosionRadius = 15.0;
maxDamage = 50.40;
destroyedLevel = 50.40;
// Afterburner and any energy weapon pool
energyPerDamagePoint = 160;
maxEnergy = 280;
rechargeRate = 0.8;
minDrag = 40; // Linear Drag (eventually slows you down when not thrusting...constant drag)
rotationalDrag = 20; // Anguler Drag (dampens the drift after you stop moving the mouse...also tumble drag)
maxAutoSpeed = 10; // Autostabilizer kicks in when less than this speed. (meters/second)
autoAngularForce = 400; // 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 = 4; // 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 = 6400; // Horizontal jets (W,S,D,A key thrust)
steeringForce = 500; // Steering jets (force applied when you move the mouse)
steeringRollForce = 200; // Steering jets (how much you heel over when you turn)
rollForce = 10; // Auto-roll (self-correction to right you after you roll/invert)
hoverHeight = 0.5; // Height off the ground at rest
createHoverHeight = 0.5; // Height off the ground when created
maxForwardSpeed = 90; // speed in which forward thrust force is no longer applied (meters/second)
// Turbo Jet
jetForce = 3000; // Afterburner thrust (this is in addition to normal thrust)
minJetEnergy = 28; // Afterburner can't be used if below this threshhold.
jetEnergyDrain = 2.8; // Energy use of the afterburners (low number is less drain...can be fractional)
vertThrustMultiple = 3.0; // Auto stabilize speed
// Rigid body
mass = 100; // Mass of the vehicle
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.
softImpactSpeed = 3; // Sound hooks. This is the soft hit.
hardImpactSpeed = 15;// Sound hooks. This is the hard hit.
// Ground Impact Damage (uses DamageType::Ground)
minImpactSpeed = 10; // If hit ground at speed above this then it's an impact. Meters/second
speedDamageScale = 0.06;
// Object Impact Damage (uses DamageType::Impact)
collDamageThresholdVel = 23.0;
collDamageMultiplier = 0.02;
// Contrails
minTrailSpeed = 15; // The speed your contrail shows up at.
trailEmitter = FighterContrailEmitter;
forwardJetEmitter = FighterFJetEmitter;
downJetEmitter = FighterDJetEmitter;
triggerDustHeight = 4.0;
dustHeight = 1.0;
damageEmitterOffset[0] = "0.0 -3.0 0.0 ";
damageLevelTolerance[0] = 0.3;
damageLevelTolerance[1] = 0.7;
numDmgEmitterAreas = 3;
checkRadius = 5.5;
observeParameters = "0 0 1";
shieldEffectScale = "0.937 1.125 0.60";
};
//----------------------------------------------------------------------------------------
// Game Functions
//----------------------------------------------------------------------------------------
function Flyer::onDamage(%this, %obj, %delta)
{
Parent::onDamage(%this, %obj);
%currentDamage = %obj.getDamageLevel();
if(%currentDamage > %obj.destroyedLevel)
{
if(%obj.getDamageState() !$= "Destroyed")
{
if(%obj.respawnTime !$= "")
%obj.marker.schedule = %obj.marker.data.schedule(%obj.respawnTime, "respawn", %obj.marker);
%obj.setDamageState(Destroyed);
}
}
else
{
if(%obj.getDamageState() !$= "Enabled")
%obj.setDamageState(Enabled);
}
}
#11
game.cs
02/22/2008 (9:00 pm)
And due to post length issues;game.cs
function onServerCreated()
{
// This function is called when a server is constructed.
// Master server information for multiplayer games
$Server::GameType = "Torque TTB";
$Server::MissionType = "None";
// Load up all datablocks, objects etc.
exec("./audioProfiles.cs");
exec("./camera.cs");
exec("./editor.cs");
exec("./jet.cs");
}
function onServerDestroyed()
{
// This function is called as part of a server shutdown.
}
//-----------------------------------------------------------------------------
function onMissionLoaded()
{
// Called by loadMission() once the mission is finished loading.
new ScriptObject(AIManager) {};
MissionCleanup.add(AIManager);
AIManager.think();
}
function onMissionEnded()
{
// Called by endMission(), right before the mission is destroyed
AIManager.delete();
}
//-----------------------------------------------------------------------------
// Dealing with client connections
// These methods are extensions to the GameConnection class. Extending
// GameConnection make is easier to deal with some of this functionality,
// but these could also be implemented as stand-alone functions.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function GameConnection::onClientEnterGame(%this)
{
// Every client get's a camera object.
%this.camera = new Camera() {
dataBlock = Observer;
};
MissionCleanup.add( %this.camera );
%this.camera.scopeToClient(%this);
// Create a player object.
%spawnPoint = pickSpawnPoint();
%this.createPlayer(%spawnPoint);
}
function GameConnection::onClientLeaveGame(%this)
{
if (isObject(%this.camera))
%this.camera.delete();
if (isObject(%this.player))
%this.player.delete();
}
//-----------------------------------------------------------------------------
function GameConnection::createPlayer(%this, %spawnPoint)
{
if (%this.player > 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!" );
}
// Create the player object
%player = new Player(player) {
dataBlock = Jet;
client = %this;
};
MissionCleanup.add(%player);
// Player setup...
%player.setTransform(%spawnPoint);
%player.setShapeName(%this.name);
// Update the camera to start with the player
%this.camera.setTransform(%player.getEyeTransform());
// Give the client control of the player
%this.player = %player;
%this.setControlObject(%player);
}
//-----------------------------------------------------------------------------
function pickSpawnPoint()
{
// Pick the first object in drop point group and use it's
// location as a spawn point.
%group = nameToID("MissionGroup/PlayerDropPoints");
if (%group != -1 && %group.getCount() != 0)
return %group.getObject(0).getTransform();
// If no object was found, return a point near the center of the world
error("Missing spawn point object and/or mission group " @ %groupName);
return "0 0 300 1 0 0 0";
}
#12
02/22/2008 (9:49 pm)
This also happened to me. This is what I do...When it freezes, I just a click a few times until the top (where it's blue) says "Not Responding." Next, I wait for about 5 to 15 seconds. After 15 seconds, it stops freezing and it loads my mission. If that doesn't work, just be patient and wait for a minute to see if it loads ( And this time, don't click on anything).
#13
02/26/2008 (12:46 pm)
Still not working (sorry about being a pain), tried that but it wouldn't freeze and wouldn't load. Here's the files if you want to take a look at it. www.mediafire.com/?gs0dnjw0y0t
#14
Now for the Create function...
If this still doesn't work, you should try to search for a few resources. And don't worry, your not a pain :-)
02/26/2008 (6:15 pm)
I think the problem is that there isn't a create function for the Jet. I also noticed that the onDamage function says [b]Flyer[/b]::onDamage(%this, %obj, %delta)I think it should be
[b]Jet[/b]::onDamage(%this, %obj, %delta)
Now for the Create function...
function Jet::create(%vehicle)
{
%obj = new FlyingVehicle() {
dataBlock = %block;
mountable = true;
};
return(%obj);
}If this still doesn't work, you should try to search for a few resources. And don't worry, your not a pain :-)
#15
02/28/2008 (4:52 pm)
Thanks a lot for your help, got it to work. Had to replace "datablock = FlyingVehicleData" with "datablock = FlyingVehicle". A frustrating, but silly mistake. :)
Torque Owner Jamal Moon
1) Go to data/shapes/player and put your model in it. Then open player.cs (the one in the same folder as the one your avatar is in) and look for where it says baseShape = "./player.dts"; and change it to your avatar's name (for example baseShape = "./my avatar.dts";).
2) Navigate to server/scripts and open player.cs. Then scroll down to the datablock and search for shapeFile = "~/data/shapes/player/player.dts";. Change the name (for example... shapeFile = ~/data/shapes/MyNewAvatar/myAvatar.dts";).
3) Open your game, press tab and you should see your character. That should be all, if it isn't, tell me what the problem is and i'll try my best to fix it.