Game Development Community

Camera that follows the player

by Tom Perry · in TGB Platformer Kit · 03/13/2008 (10:12 am) · 11 replies

Hey, I love the PSK, really well laid out, looks easy ot expand upon. But I've hit a snag already!
I was just going through the tutorial on TDN, and perhaps I missed something, but the camera does not follow the dragon. I have just implemented the part where we create the player via a spawn point, using the alterations in the thread in this forum.
Cheers for any help.

#1
03/13/2008 (12:56 pm)
Is there anything in the console that looks out of place?

Can you please try throwing an "echo" function inside the "PlayerClass::onAddToScene()" function inside the "PlayerMethods.cs" file?

Camera mounting is done by the player's class and not by the actor behavior, maybe there is a problem with calling the class methods.
#2
03/13/2008 (1:05 pm)
Nothing in the console and the echo statement does not appear in the output. So you guessed right, there is somthing wrong when calling the class method by the looks of it.
#3
03/13/2008 (1:11 pm)
This is weird =/

When he jumps and lands, does he make a sound upon contact with the ground?
#4
03/13/2008 (1:18 pm)
Nope he doesn't. It doesn't look like PlayerMethods.cs or DrillMethods.cs are getting compiled, there are no .dso's created after running the game.
#5
03/13/2008 (1:20 pm)
Where is "PlayerMethods.cs" loaded? Mine isn't being compiled and I can't seem to find exec("./PlayerMethods.cs");

Edit:
Doh! Beaten to it.
#6
03/13/2008 (1:25 pm)
Geez, how on earth didn't I come to that conclusion? You should be able to throw them into the "game/gamescripts/game.cs" file in the "startGame()" function.
#7
03/13/2008 (1:27 pm)
Yep that was it, problem solved :D
#8
03/13/2008 (1:59 pm)
I was having a problem getting the camera to attach to the player via the 3 behavior method mentioned in the demo tutorial. The mount camera function was getting called, but for whatever reason sceneWindow2D.mount wasn't working. Using the mount command in the console did work though.

So I switched to the spawn point behavior method and but the dragon template could not be found. The datablock.cs file in the managed folder is empty, so I copied the datablock entry for the dragon template found in gameScripts datablock.cs and changing it to: new t2dSceneObjectDatablock(DragonTemplate). This allows the behavior to find the template.

Now the camera works and is attached to the player object when the scene is loaded.
#9
03/13/2008 (2:18 pm)
Mike, there is a stupid problem with TGB where it will dismount the camera on loading the level. The order of loading goes something like this:

loadLevel
For each object in scene add it to the game -> %obj.addToScene();
...
onLevelLoaded

So when an object is added to the scene and the camera is mounted to it, it gets dismounted afterwards. It means that you either have to mount the camera in the onLevelLoaded function, or add the object to the scene after the level has been loaded (which is what a spawn point does).

On another note, if I change "datablock t2dSceneObjectDatablock..." to "new ..." it will be recognised by the behaviors? I didn't know that, thanks Mike!
#10
03/13/2008 (2:27 pm)
Well, using new is how the level builder sets up datablocks in the managed folder. Just copying the dragon template from gameScripts/datablocks.cs to managed/datablocks.cs will give you a compile error. The "datablock" tag has to be changed to "new".

Changing datablock to new inside gameScripts/datablocks.cs will not allow behaviors to recognize those objects, it still has to be done through the managed/datablocks.cs.
#11
06/17/2012 (5:40 pm)
I've tried this, because I was having the same problem. But the class stuff still won't link. T2D says that it doesn't recognize the function onAddToScene - as described here:

function PlayerClass::onAddToScene( %this, %scenegraph )
{
    Parent::onAddToScene( %this, %scenegraph );
    
    %this.mountCamera();
    
    %this.updateExtraLivesGui();
    %this.updateHealthGui();
    
    // Initialise Inventory.
    %this.schedule( 0, "initInventory" );
}

So it seems to me this is probably the problem. But I don't know what to change the function name to, or why it isn't recognizing it. Maybe it's defined somewhere that isn't getting loaded?