Camera on Path
by DarqueLord · in Technical Issues · 11/25/2007 (3:39 pm) · 8 replies
Followed some scripts from another post on this but am not having any luck with this. My mission starts but the camera never moves and I never regain control of the player. I created a path in my mission editor and made all the script changes but I cant see where I have gone wrong... Can someone take a look at this to see whats wrong?
First the pathcamera.cs
//-----------------------------------------------------------------------------
// Path Camera
//-----------------------------------------------------------------------------
datablock PathCameraData(LoopingCam)
{
mode = "";
};
function LoopingCam::onNode(%this,%camera,%node)
{
if (%node == %camera.loopNode) {
%camera.pushPath(%camera.path);
%camera.loopNode += %camera.path.getCount();
}
}
function PathCamera::followPath(%this,%path)
{
%this.path = %path;
if (!(%this.speed = %path.speed))
%this.speed = 100;
if (%path.isLooping)
%this.loopNode = %path.getCount() - 2;
else
%this.loopNode = -1;
%this.pushPath(%path);
%this.popFront();
}
function PathCamera::pushPath(%this,%path)
{
for (%i = 0; %i < %path.getCount(); %i++)
%this.pushNode(%path.getObject(%i));
}
function PathCamera::pushNode(%this,%node)
{
if (!(%speed = %node.speed))
%speed = %this.speed;
if ((%type = %node.type) $= "")
%type = "Normal";
if ((%smoothing = %node.smoothing) $= "")
%smoothing = "Linear";
%this.pushBack(%node.getTransform(),%speed,%type,%smoothing);
}
Now I made some changes in the game.cs
function GameConnection::onClientEnterGame(%this)
{
commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);
// Create a new camera object.
%this.camera = new Camera() {
dataBlock = Observer;
};
MissionCleanup.add( %this.camera );
%this.camera.scopeToClient(%this);
// Create path camera
%this.PathCamera = new PathCamera() {
dataBlock = LoopingCam;
position = "0 0 300 1 0 0 0";
};
%this.PathCamera.followPath("MissionGroup/Path1");
MissionCleanup.add( %this.PathCamera);
%this.PathCamera.scopeToClient(%this);
$Server::Client = %this;
%this.setControlObject(%this.PathCamera);
}
function GameConnection::onClientLeaveGame(%this)
{
if (isObject(%this.camera))
%this.camera.delete();
if (isObject(%this.player))
%this.player.delete();
}
Next I change the Gameconnection::Create player method...
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 = PlayerBody;
client = %this;
};
MissionCleanup.add(%player);
// Player setup...
%player.setTransform(%spawnPoint);
%player.setEnergyLevel(60);
%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);
%this.pathCamera = new PathCamera() {
dataBlock = LoopingCam;
};
%this.pathCamera.followPath( "MissionGroup/Path1");
%this.schedule(6500, "MissionCleanup.add", %this.player);
%this.schedule(7000, "setControlObject", %this.player);
MissionCleanup.add( %this.pathCamera );
%this.setControlObject(%this.pathCamera);
}
If you can post your finding here then that would be greatly appreciated... trying to get the camera to follow the path once and then have the normal camera take control again. DL out.
First the pathcamera.cs
//-----------------------------------------------------------------------------
// Path Camera
//-----------------------------------------------------------------------------
datablock PathCameraData(LoopingCam)
{
mode = "";
};
function LoopingCam::onNode(%this,%camera,%node)
{
if (%node == %camera.loopNode) {
%camera.pushPath(%camera.path);
%camera.loopNode += %camera.path.getCount();
}
}
function PathCamera::followPath(%this,%path)
{
%this.path = %path;
if (!(%this.speed = %path.speed))
%this.speed = 100;
if (%path.isLooping)
%this.loopNode = %path.getCount() - 2;
else
%this.loopNode = -1;
%this.pushPath(%path);
%this.popFront();
}
function PathCamera::pushPath(%this,%path)
{
for (%i = 0; %i < %path.getCount(); %i++)
%this.pushNode(%path.getObject(%i));
}
function PathCamera::pushNode(%this,%node)
{
if (!(%speed = %node.speed))
%speed = %this.speed;
if ((%type = %node.type) $= "")
%type = "Normal";
if ((%smoothing = %node.smoothing) $= "")
%smoothing = "Linear";
%this.pushBack(%node.getTransform(),%speed,%type,%smoothing);
}
Now I made some changes in the game.cs
function GameConnection::onClientEnterGame(%this)
{
commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);
// Create a new camera object.
%this.camera = new Camera() {
dataBlock = Observer;
};
MissionCleanup.add( %this.camera );
%this.camera.scopeToClient(%this);
// Create path camera
%this.PathCamera = new PathCamera() {
dataBlock = LoopingCam;
position = "0 0 300 1 0 0 0";
};
%this.PathCamera.followPath("MissionGroup/Path1");
MissionCleanup.add( %this.PathCamera);
%this.PathCamera.scopeToClient(%this);
$Server::Client = %this;
%this.setControlObject(%this.PathCamera);
}
function GameConnection::onClientLeaveGame(%this)
{
if (isObject(%this.camera))
%this.camera.delete();
if (isObject(%this.player))
%this.player.delete();
}
Next I change the Gameconnection::Create player method...
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 = PlayerBody;
client = %this;
};
MissionCleanup.add(%player);
// Player setup...
%player.setTransform(%spawnPoint);
%player.setEnergyLevel(60);
%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);
%this.pathCamera = new PathCamera() {
dataBlock = LoopingCam;
};
%this.pathCamera.followPath( "MissionGroup/Path1");
%this.schedule(6500, "MissionCleanup.add", %this.player);
%this.schedule(7000, "setControlObject", %this.player);
MissionCleanup.add( %this.pathCamera );
%this.setControlObject(%this.pathCamera);
}
If you can post your finding here then that would be greatly appreciated... trying to get the camera to follow the path once and then have the normal camera take control again. DL out.
#2
11/25/2007 (6:07 pm)
I will try that Brian. However doesnt the line %this.pathCamera.followPath( "MissionGroup/Path1"); actually tell the camera what to do? Im just guessing. Thanks, DL out.
#3
11/25/2007 (6:26 pm)
Well that didnt work... Might try something a little different. I dont understand how come this works for one person and not someone else. DL out.
#4
"A computer will never do what you want it to do, but it will ALWAYS do what you tell it to do"
Although i know how hard it sucks when you find a tutorial and think: cool lets try it out, and it seems that whatever you do, it wont work. But, 99% of these tutorials eventually has shown up to work, at least for me.
And we see that Darque lord is posting each time, your name is next to your post, so there is no need for that cheesy DL out =)
11/26/2007 (6:44 am)
That sounds paranoid. Most likely, u have missed something along the lines. There is a cool old programming quote that you could use: "A computer will never do what you want it to do, but it will ALWAYS do what you tell it to do"
Although i know how hard it sucks when you find a tutorial and think: cool lets try it out, and it seems that whatever you do, it wont work. But, 99% of these tutorials eventually has shown up to work, at least for me.
And we see that Darque lord is posting each time, your name is next to your post, so there is no need for that cheesy DL out =)
#5
11/26/2007 (9:16 am)
Whoa that was so helpful, thanks for being part of the solution there TedHehdjedkj. Im not a coder so its pretty hard for me to grasp alot of this. Its like trying to read ancient text without the Rosetta stone. Anyway, hope someone can help me and point out where I have missed this. Thanks!
#6
also:
this won't work because it'll be looking for a MissionCleanup.add function for the connection object, which doesn't have one. you should do it like this:
but you really don't need a schedule for this. why wait? just call MissionCleanup.add() right there and be done with it.
11/26/2007 (11:46 am)
Darque you need to check the console.log file in the .exe folder. most likely you have an error in your script which is keeping things from working. your script looks confusing. you're calling setControlObject 3 times but you only should be calling it once. and where is createplayer being called from?also:
%this.schedule(6500, "MissionCleanup.add", %this.player);
this won't work because it'll be looking for a MissionCleanup.add function for the connection object, which doesn't have one. you should do it like this:
MissionCleanup.schedule(6500, "add", %this.player);
but you really don't need a schedule for this. why wait? just call MissionCleanup.add() right there and be done with it.
#7
11/26/2007 (12:23 pm)
Thanks Sean. Im gonna go back over the code again. Also I checked the console log and only found errors for some DTS models. There were no errors for scripting. Im still learning and dont really understand Torquescript that well. Thanks again.
#8
11/30/2007 (10:06 pm)
Still no luck with this... Can some please test this and help me out? Thanks!
Torque Owner Michael Bacon
Default Studio Name
Try adding %this.pathCamera.setState("forward") at the end of createPlayer();