Camera Mounting/Unmounting
by Brian Wilson · in Torque Game Builder · 04/11/2005 (9:17 am) · 11 replies
I'm certain that I've seen at least one thread on this subject before, but for the life of me, I cannot find it now.
Basically what I'm trying to is have the camera mounted to my $player until he nears the edge of my map/level/etc, then unmount the camera and allow the $player to continue on toward the edge. Then once the $player moves back toward the center, remount the camera so that it focuses on the $player as he moves around. We've all seen this effect in just about every 2d game out there.
Here's an illustration of what I'm trying to do:

I can mount the camera onto the player with:
but it's the unmounting that I'm having the problem with. I had assumed there was an unmount() function, but I'm not certain. I'm sure it's also possible that I should issue another sceneWindow2d.mount(???) to focus the camera elsewhere. I could do this with a hack by placing a an visible(false) sprite at each corner of my threshold box and mounting to that, but I'm not sure that's the best way to do that.
Any pointers?
Basically what I'm trying to is have the camera mounted to my $player until he nears the edge of my map/level/etc, then unmount the camera and allow the $player to continue on toward the edge. Then once the $player moves back toward the center, remount the camera so that it focuses on the $player as he moves around. We've all seen this effect in just about every 2d game out there.
Here's an illustration of what I'm trying to do:

I can mount the camera onto the player with:
sceneWindow2D.mount($player);
but it's the unmounting that I'm having the problem with. I had assumed there was an unmount() function, but I'm not certain. I'm sure it's also possible that I should issue another sceneWindow2d.mount(???) to focus the camera elsewhere. I could do this with a hack by placing a an visible(false) sprite at each corner of my threshold box and mounting to that, but I'm not sure that's the best way to do that.
Any pointers?
#2
04/11/2005 (9:35 am)
Hah! Thanks John. I knew it was a simple solution, I had just hit a brick wall. I guess my unix background put a mental lock on "umount/unmount".
#3
04/11/2005 (10:07 pm)
As an additional question, is my approach even remotely solid for this problem? Or is there a better way?
#4
04/11/2005 (10:11 pm)
I thought that the camera would not go past the edge of a map if it's mounted to the player. Doesn't it do what you described automatically?
#5
04/11/2005 (10:25 pm)
No, when I mount the camera to the player, it stays centered on the player all the way to the edge of the map, thus in my diagram above with the player in the absolute lower left, the lower left of the map displays at -1x/+1y of the player instead of stoping at the lower left corner of the window/screen.
#6
04/11/2005 (10:28 pm)
What you could do is create a sceneObject that follows the player(with its world limits enough inside the players that it won't view off the map) then mount the camera to it, so as the player nears the object stops.
#8
04/12/2005 (12:53 am)
If memory serves me, there's a world-limit property for the camera that is valid even when mounted to an object. Ah, here it is:setViewLimitOn(minX / minY / maxX / maxY)and
setViewLimitOff()
Quote:When the view limit is on, the camera will not be allowed to view outside this area, whether the camera is mounted, zoomed, moved, interpolating, whatever
#9
The above assumes that my overall map size is 200x150 units. And playing with the mount stickyness creates some very nice effect.
I made this much more difficult that it should have been when I first set out. I think I actually touched on the above solution, but just didn't get the combinations correct the first time.
@Teck
Thanks for pointing me in the correct direction.
04/12/2005 (7:17 am)
I actually achieved the effect I was looking for with the following code:sceneWindow2D.mount($player);
sceneWindow2D.setViewLimitOn("-100 -75 100 75");The above assumes that my overall map size is 200x150 units. And playing with the mount stickyness creates some very nice effect.
I made this much more difficult that it should have been when I first set out. I think I actually touched on the above solution, but just didn't get the combinations correct the first time.
@Teck
Thanks for pointing me in the correct direction.
#10
@Teck: thx for the post... I didn't get a chance to look it up, great command!
lol Melv really did think of just about everything
04/12/2005 (9:25 am)
Glad you got it working!@Teck: thx for the post... I didn't get a chance to look it up, great command!
lol Melv really did think of just about everything
#11
sceneWindow2D.mount($player);
sceneWindow2D.setViewLimitOn("-48 40 150 -50");
you will want to change the "$player" to whatever you have your sceneobject named...also, you may have to tweak around and modify the numbers so that they fit your particular camera view--"-48" is my minimum X for my screen, 40 is the minimum y, 150 is the maximum X, and -50 is the maximum Y. Hope this can help someone else who may be struggling w/ camera mounts! Peace.
02/01/2008 (7:46 am)
For those who are having a difficult time w/ camera mounting (like I was earlier before I read this post), here's an awesomely simple way to mount the camera to your player:sceneWindow2D.mount($player);
sceneWindow2D.setViewLimitOn("-48 40 150 -50");
you will want to change the "$player" to whatever you have your sceneobject named...also, you may have to tweak around and modify the numbers so that they fit your particular camera view--"-48" is my minimum X for my screen, 40 is the minimum y, 150 is the maximum X, and -50 is the maximum Y. Hope this can help someone else who may be struggling w/ camera mounts! Peace.
Torque Owner John Vanderbeck
VanderGames