Game Development Community

Mount to Camera?

by Eric Robinson · in Torque Game Builder · 04/05/2007 (12:18 am) · 5 replies

I'm trying to lock certain objects relative to the camera in my platformer-style game. I've thought of several things, none of which am I sure how to do (or if they're even possible):

1) Embed a t2dSceneGraph within a t2dSceneGraph. This would allow me to isolate the movement (camera is set to follow the player) and apply it to only certain objects within the level. The idea is that the "moving" t2dSceneGraph would be an object within the static t2dSceneGraph.

2) Mount objects to the camera. I don't see any methods for this so I've been assuming it's not possible.

3) Check every scene update for the camera's current position and move then items I want locked to the relative position within the camera area. Rough but doable.

Anyone have any thoughts? Are any or all of the above doable?

#1
04/07/2007 (2:50 am)
Mount the camera to a scene object with no force, and then, think about this object as the camera itself.
It's the base if you want to keep a good track of it (and also to mount objects to it). Then mount this camera object (with some force) to the target you want. Then code your script with the camera object in mind.
Thats simple ^^
#2
04/07/2007 (4:56 am)
I've used option 1 and it works fairly well. Except, it's not actually embedding a scenegraph in a scenegraph, it's just stand alone scenegraphs, one on top of the other. This is good for things like the HUD.
#3
04/07/2007 (5:05 am)
@Eric: Check out my plan. You can easily do this by having a second scenewindow with a seperate scenegraph.
#4
04/08/2007 (4:28 am)
@Ben: Yeah, I tried that but got some really funny jittering. Things also wouldn't stay still the way I wanted them to because I wanted to use camera boundaries (object boundaries in the model you mentioned above) and not everything wanted to play correctly.

Incidentally, the function "getCurrentCameraPosition()" gets the position that the camera is supposed to be in prior to any modifications the engine makes with the camera's view boundaries. Really strange.

@Andrew: This is actually how I solved the problem. Going through it also gave me a MUCH better understanding of the way TGB works and is a lot cleaner/more stable. Love it.

@Oliver: That's actually what I ended up doing. I use three scenewindows with three scenegraphs: one for the background layer, one for the game layer (resized to fit the window the way I want it to) and then one for the foreground. The foreground layer was a little tricky because you need to make it transparent. I learned that little trick from this tutorial.

I realize that it's probably wasting some space to use three scenegraphs (especially when I only need for-the-most-part static images). When I get some free time I'll look into adding the assets to the main game's scene graph and then tell the scene windows to look 'way off in the distance' somewhere for them. Tutorial for this is here. Good stuff!

Have you considered turning your plan into a tutorial for TDN?

Thanks for all the help guys!
#5
04/08/2007 (9:38 am)
@Eric: Yeah that tutorial was a great addition to the TDN.. and yes, I planned to.. I was very busy with my study lately and didn't get around to code much hence no more .plans but that changed now. I am still busy catching up though. :)