How do I make the camera follow a path using path camera?
by Jose M Euvin · in Torque 3D Professional · 04/02/2012 (4:25 am) · 6 replies
Here is my problem, I'm trying to implement a PathCamera in my game. I'm not getting any errors in the console, but the damn thing is not doing anything.
This piece of code was added in core/art/datablocks/camera.cs
First:
I then add this portion of code in my mission file.
Then:
I created pathCam.cs and added the following. I'm also executing it this file in /scripts/client/init.cs
When I test my function in the console i type in setPathCamera(myPath) and nothing happens.
After I reset by typing in cleanTestPathCamera the camera moves to the spawnpoint and returns to the previous camera mode. I also try using:
I even try using $Camera.setTarget(1), 2, 3 etc...
myPath.setTarget(0.1), 0.2, 0.3 etc
and $Camera.setTarget(0.1), 0.2, 0.3 etc
Not sure what I'm missing, someone please help.
Thank you.
This piece of code was added in core/art/datablocks/camera.cs
First:
//new path cam datablock
datablock PathCameraData(CamPath)
{
};I then add this portion of code in my mission file.
new SimGroup(Paths)
{
new Path(CameraPathModel) {
isLooping = "1";
canSave = "1";
canSaveDynamicFields = "1";
new Marker() {
seqNum = "1";
type = "Normal";
msToNext = "1000";
smoothingType = "Linear";
position = "-25.0275 -11.5198 1.51868";
rotation = "1 0 0 0";
scale = "1 1 1";
canSave = "1";
canSaveDynamicFields = "1";
speed = "5";
};
new Marker() {
seqNum = "2";
type = "Normal";
msToNext = "1000";
smoothingType = "Linear";
position = "-25.0275 -12.5198 1.51868";
rotation = "1 0 0 0";
scale = "1 1 1";
canSave = "1";
canSaveDynamicFields = "1";
speed = "5";
};
new Marker() {
seqNum = "3";
type = "Normal";
msToNext = "1000";
smoothingType = "Linear";
position = "-25.0275 -13.5198 1.51868";
rotation = "1 0 0 0";
scale = "1 1 1";
canSave = "1";
canSaveDynamicFields = "1";
speed = "5";
};
};
};Then:
I created pathCam.cs and added the following. I'm also executing it this file in /scripts/client/init.cs
$Camera = localclientconnection.camera;
function testPathCamera()
{
%p = createCameraPath(CameraPathModel);
//saves our current camera
$savecamera = localclientconnection.camera;
//replace our current camera with our path camera
localclientconnection.camera = %p;
//binds the camerea to our new path camera
LocalClientConnection.setControlObject(localclientconnection.camera);
//moves the path camerea to our targt position
if(isObject(CameraPathModel))
setPathCamera(CameraPathModel);
}
function setPathCamera(%path)
{
for(%i = 0; %i <%path.getCount(); %i++)
localclientconnection.camera.setTarget(%i);
}
function cleanTestPathCamera()
{
$Camera.delete();
$Camera = $savecamera;
localclientconnection.setControlObject($Camera);
}
function createCameraFollowPath(%path,%name)
{
if( isObject(%path) && %path.getCount())
{
%pathNode = %path.getObject(0);
%transform = %pathNode.getTransform();
%pos = getWords( %transform, 0 ,2 );
%rot = getWords( %transform, 3 ,6 );
%p = new PathCamera(myPath) {
dataBlock = CamPath;
position = %pos;
rotation = %rot;
};
for(%i = 1; %i < %path.getCount(); %i++)
{
%pathNode = %path.getObject(%i);
%transform = %pathNode.getTransform();
%p.pushBack(%transform,2,"Normal","Spline");
}
return %p;
}
}When I test my function in the console i type in setPathCamera(myPath) and nothing happens.
After I reset by typing in cleanTestPathCamera the camera moves to the spawnpoint and returns to the previous camera mode. I also try using:
I even try using $Camera.setTarget(1), 2, 3 etc...
myPath.setTarget(0.1), 0.2, 0.3 etc
and $Camera.setTarget(0.1), 0.2, 0.3 etc
Not sure what I'm missing, someone please help.
Thank you.
#2
04/03/2012 (3:21 am)
//this is the funtion I'mm testing in the console
function testPathCamera()
{
//here I make an external call to createCameraPath, to create a new path camera dynamically.
%p = createCameraPath(CameraPathModel);
//saves our current camera
$savecamera = localclientconnection.camera;
//replace our current camera with our path camera
[b]//Not sure if I'm doing this right at this point need help here
localclientconnection.camera = %p; [/b]
//binds the camerea to our new path camera
LocalClientConnection.setControlObject(localclientconnection.camera);
//moves the path camerea to our targt position
//for this test mid way.
%p.setTarget(".50");
}
//this function is which creates the path camera and pushes every node to it.
function createCameraPath(%path)
{
//if the object exits and its not null
if( isObject(%path) && %path.getCount())
{
//we use the node of the path created in the mission file to get the first node in it to set the position of our path camera.
%pathNode = %path.getObject(0);
%transform = %pathNode.getTransform();
%pos = getWords( %transform, 0 ,2 );
%rot = getWords( %transform, 3 ,6 );
//create our path camera with our new position
%p = new PathCamera() {
dataBlock = CamPath;
position = %pos;
rotation = %rot;
};
//go through every maker and push it to our new path camera
for(%i = 0; %i < %path.getCount(); %i++)
{
%pathNode = %path.getObject(%i);
%transform = %pathNode.getTransform();
%p.pushBack(%transform,2,"Normal","Spline");
}
//returns or new camera to our temporary variable in testPathCamera()
return %p;
}
}
#3
I put tons of comments, maybe this will help explain myself and maybe you can give me some feedback to where I'm going wrong.
Currently the camera does not do anything and it does not return any errors in the console either.
Thanks.
04/03/2012 (3:46 am)
Daniel, I put tons of comments, maybe this will help explain myself and maybe you can give me some feedback to where I'm going wrong.
Currently the camera does not do anything and it does not return any errors in the console either.
Thanks.
#4
04/03/2012 (6:06 am)
Have you tried setting the camera to NewtonFlyMode? Check the documentation on advanced camera modes and also the Torque Script chm file.
#5
04/03/2012 (6:07 am)
I did, but it causes the screen to shake and bounce back and forth. Its not doing what I want it to do.
#6
www.garagegames.com/community/forums/viewthread/130089
04/10/2012 (4:03 am)
See this post for my working version of Path Camera.www.garagegames.com/community/forums/viewthread/130089
Torque Owner Daniel Buckmaster
T3D Steering Committee
Might be a good idea to do some echo debugging to see if all your objects are created as you expect. Also, what is the createCameraPath function? You've got one called createCameraFollowPath.