Mounting the camera to my player.
by Storm Kiernan · in Torque Game Builder · 06/13/2011 (8:13 pm) · 4 replies
I want the camera to follow my player. My assumption is that to do this I need to mount the sceneWindow2D to my player.
Here is my attempt at doing this:
The trouble is that the camera does not move with the player...
Here is my attempt at doing this:
function Person::onAdd(%this)
{
if(!isObject($PersonGroup))
{
$PersonGroup = new SimSet();
}
if(!isObject($player))
{
if(sceneWindow2D.getIsCameraMounted())
{
sceneWindow2D.dismount();
}
sceneWindow2D.mount(%this);
$player = %this;
}
else
{
%this.schedule(0, "aiThink");
}
$PersonGroup.add(%this);
}The trouble is that the camera does not move with the player...
#2
tdn.garagegames.com/wiki/TGB/Tutorials/Platformer/Camera
06/15/2011 (6:26 am)
The following behavior script is quite awesome if you haven't seen it. It allows you to easily set up camera bounds and stuff in the scene editor using the world bounds of a scene object. You can get the script and read the instructions here:tdn.garagegames.com/wiki/TGB/Tutorials/Platformer/Camera
#3
This should give the engine enough time to initialize the object to a point where it's possible to mount things appropriately.
06/15/2011 (6:28 am)
I don't believe there is. You could setup a scheduled call inside of onAdd, with a minor delay to help with that issue. One example might befunction Player::onInit(%this) {
//attach your camera code here
}
function Player::onAdd(%this) {
%this.schedule(500, onInit);
}This should give the engine enough time to initialize the object to a point where it's possible to mount things appropriately.
#4
smally, I did not end up testing your code since my code had worked prior to my seeing your post. although it is helpful to know that can be done!
Cory Leach, thank you for the link. I need to keep my nose in that section of tdn.
06/15/2011 (12:05 pm)
The fix to this was to create a scene object that was called GameStateManager and then use the onLevelLoaded for that object to manage the cameras mount.smally, I did not end up testing your code since my code had worked prior to my seeing your post. although it is helpful to know that can be done!
Cory Leach, thank you for the link. I need to keep my nose in that section of tdn.
Torque Owner Storm Kiernan
Default Studio Name