Having Camera Follow Ball
by Pesto126 · in Torque Game Builder · 11/19/2007 (3:24 pm) · 13 replies
Newb alert here.. I created a world limit that is taller than the screen.. my goal is to get a ball to drop from the visible top, hit a bat and then go back up and out of the view.. but I want the camera to follow the ball to the top of the world limit.. a quick drawing to explain:
= is the top of the world
- is the what the user can see on screen.. so ball travels from - to bat and then rises above - to =.. I want camera to follow ball to =
=========================================
---------------------------------------------------------------------------
o - Ball
***** - Bat
---------------------------------------------------------------------------
==========================================
Now, I tried the following code in a new .cs file (ball.cs) and it doesn't work:
function ballclass::onLevelLoaded(%this, %scenegraph)
{
%this.setLinearVelocityY(20);
%force = 20;
sceneWindow2D.mount(%this, "0 0", %force, true);
}
I have a ball assigned the ballclass... the ball.cs get exec.. in the main.cs... so, I thought when the level was loaded and the ball was drawn, it would get the camera attached to it via this function.. nothing I've tried worked.. any help please?
Thx!
= is the top of the world
- is the what the user can see on screen.. so ball travels from - to bat and then rises above - to =.. I want camera to follow ball to =
=========================================
---------------------------------------------------------------------------
o - Ball
***** - Bat
---------------------------------------------------------------------------
==========================================
Now, I tried the following code in a new .cs file (ball.cs) and it doesn't work:
function ballclass::onLevelLoaded(%this, %scenegraph)
{
%this.setLinearVelocityY(20);
%force = 20;
sceneWindow2D.mount(%this, "0 0", %force, true);
}
I have a ball assigned the ballclass... the ball.cs get exec.. in the main.cs... so, I thought when the level was loaded and the ball was drawn, it would get the camera attached to it via this function.. nothing I've tried worked.. any help please?
Thx!
About the author
#2
--Have you used Torsion and set a breakpoint on the line :
To confirm it's actually being executed?
--Have you confirmed that your scene window is actually named sceneWindow2D?
--Are you getting any warnings in your console?
On the general nature of asking questions, these are many of the "first level of information" questions that need answers before anyone can provide a meaningful insight to your issue. Many times without this information as part of the question itself, people will skim past your question and move on to others, so it can be a good habit to provide this type of additional information about your issue from the beginning :)
11/20/2007 (7:30 am)
General troubleshooting:--Have you used Torsion and set a breakpoint on the line :
sceneWindow2D.mount(....);
To confirm it's actually being executed?
--Have you confirmed that your scene window is actually named sceneWindow2D?
--Are you getting any warnings in your console?
On the general nature of asking questions, these are many of the "first level of information" questions that need answers before anyone can provide a meaningful insight to your issue. Many times without this information as part of the question itself, people will skim past your question and move on to others, so it can be a good habit to provide this type of additional information about your issue from the beginning :)
#3
11/20/2007 (8:38 am)
Thx Stephen... I'll check the scene window.. odds are that is it. I am not using torsion - I am using codeweaver and textpad.. I'll look into torsion..
#4
11/20/2007 (9:55 am)
Well.. this still didn't work.. in fact, once I name the main scene as sceneWindow2D... it doesn't even draw the bat/ball... I removed the mount code and with the name setup as sceneWindow2D... the bat/ball still doesn't draw. Remove the scene name.. and it works.. Any advice? I cannot believe I can't get this simple thing to work..
#5
11/20/2007 (10:03 am)
What is the main scene called? Instead of sceneWindow2D, shouldn't it be that name? Perhaps I missed something.
#6
sceneWindow... I also modified my code in my ball.cs program (which is in the games/Baseball/game/gameScripts directory and called with an exec in the main.cs) to be:
function ballclass::onLevelLoaded(%this, %scenegraph)
{
%this.setLinearVelocityY(20);
%force = 20;
sceneWindow.mount(%this, "0 0", %force, true);
}
No dice.. the bat and ball display.. I hit the ball and the ball just floats out of view.. my camera doesn't follow the ball up the screen away from the bat.
Thx again for the help... I can always post a zip file if that would help..
11/20/2007 (10:37 am)
Ok.. under the Scene Graph Scripting panel when I click on the background grid.. I named it:sceneWindow... I also modified my code in my ball.cs program (which is in the games/Baseball/game/gameScripts directory and called with an exec in the main.cs) to be:
function ballclass::onLevelLoaded(%this, %scenegraph)
{
%this.setLinearVelocityY(20);
%force = 20;
sceneWindow.mount(%this, "0 0", %force, true);
}
No dice.. the bat and ball display.. I hit the ball and the ball just floats out of view.. my camera doesn't follow the ball up the screen away from the bat.
Thx again for the help... I can always post a zip file if that would help..
#7
I'm also wondering if there are any compilation errors. The script isn't going to run at all if it's not being compiled. Have you checked the console.log for any errors? Torsion would report them automatically for you if there were errors, for what it's worth.
11/20/2007 (11:52 am)
Well, I'm still wondering if the code is being called at all (if you don't have time to use a breakpoint in Torsion, then put a line in like:echo("Yep, we're in ballclass::onLevelLoaded!");I'm also wondering if there are any compilation errors. The script isn't going to run at all if it's not being compiled. Have you checked the console.log for any errors? Torsion would report them automatically for you if there were errors, for what it's worth.
#8
the echo appeared.. and then.. an error on the line which says..
Unknown command mount
Object sceneWindow(1341) sceneWindow -> t2dSceneGraph -> Simset -> SimObject
So.. I'm getting to the echo.. then the error for the mount command... I wish I could get Torsion to work with Debug.. the documentation is no where to be found on how to set this up logically with TGB - the forums at sickgames point to garagegames which gives you an error message...
11/20/2007 (12:31 pm)
Well.. opening the console in game gave me the following:the echo appeared.. and then.. an error on the line which says..
Unknown command mount
Object sceneWindow(1341) sceneWindow -> t2dSceneGraph -> Simset -> SimObject
So.. I'm getting to the echo.. then the error for the mount command... I wish I could get Torsion to work with Debug.. the documentation is no where to be found on how to set this up logically with TGB - the forums at sickgames point to garagegames which gives you an error message...
#9
11/20/2007 (1:20 pm)
Ok.. I finally got Torsion to work properly with the Debug.. the problem now is that the code is invalid.. so I removed it from ball.cs and now I'm trying to find another place to put it.. oh the problems with such a simple example..
#10
11/20/2007 (2:17 pm)
Pesto, it seems like you have named your scenegraph "scenewindow", which is confusing. Scenegraphs can't mount to things, but sceneWindows (the GUI element/camera into your sceneview) can. Try going back to "scenewindow2d.mount(...)", since you probably haven't changed the name of your scenewindow in your gui, and scenewindow2d is the default.
#11
11/23/2007 (7:50 am)
Intereting.. when I try typing in scenewindow2d. in torsion.. it lists all the methods available.. and .mount is NOT listed... so I must not have set something up correctly in TGB editor? I don't have a GUI at the moment and haven't specifically defined a camera or anything else.. should I have? Anyone have some samples that show a camera following an object setup in TGB editor? Thx.
#12
You can find it in: projectfolder -> game -> gui -> mainscreen.gui
It looks like:
In order to see any "sceneobjects" in your game you must have a t2dSceneWindow in your gui, which of course mainscreen does, and as you see above it is called "sceneWindow2D".
It looks to me like the code from your first post is perfectly correct. Mount IS a valid method for a t2dscenewindow's (note: t2dscenewindow is the name of the class, scenewindow2D is the name of the instance/object). I wouldn't trust torsions intellisense completely by the way. Don't forget to make use of the html based documentation to look up methods of tgb classes, or use the torsion code browser (the tab next to the "project" tab, which normally shows your project directory).
If its still not working for you I would need more information on exactly what you have done so far, because its hard to say what step you may have skipped.
11/23/2007 (5:27 pm)
When you create a new project in TGB it automatically creates a gui for you.You can find it in: projectfolder -> game -> gui -> mainscreen.gui
It looks like:
//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(mainScreenGui) {
canSaveDynamicFields = "0";
Profile = "GuiBlackContentProfile";
HorizSizing = "width";
VertSizing = "height";
Position = "0 0";
Extent = "1024 768";
MinExtent = "8 8";
canSave = "1";
Visible = "1";
useVariable = "0";
new t2dSceneWindow(sceneWindow2D) {
canSaveDynamicFields = "0";
Profile = "GuiContentProfile";
HorizSizing = "width";
VertSizing = "height";
Position = "0 0";
Extent = "1024 768";
MinExtent = "8 8";
canSave = "1";
Visible = "1";
lockMouse = "0";
useWindowMouseEvents = "1";
useObjectMouseEvents = "1";
};
};
//--- OBJECT WRITE END ---This gui is named "MainScreenGui", and if you are curious you can find-in-files using torsion (ctrl shift f) to find all references to it. You can then see where this file is executed, and where this gui is "made active".In order to see any "sceneobjects" in your game you must have a t2dSceneWindow in your gui, which of course mainscreen does, and as you see above it is called "sceneWindow2D".
It looks to me like the code from your first post is perfectly correct. Mount IS a valid method for a t2dscenewindow's (note: t2dscenewindow is the name of the class, scenewindow2D is the name of the instance/object). I wouldn't trust torsions intellisense completely by the way. Don't forget to make use of the html based documentation to look up methods of tgb classes, or use the torsion code browser (the tab next to the "project" tab, which normally shows your project directory).
If its still not working for you I would need more information on exactly what you have done so far, because its hard to say what step you may have skipped.
#13
11/24/2007 (6:37 am)
Ok.. as expected.. it is my fault. I moved the code to a new onCollision function and it worked.. I'm getting some funky stuff with the bat now.. but I'll deal with that later. Thx for all the help... I'm slowly learning and enjoying the process - and I appreciate the feedback!!
Torque Owner Pesto126