Non-rectangular camera world bounds?
by Bryant Drew Jones · in Torque X 2D · 01/22/2010 (6:54 pm) · 5 replies
Hello :)
I'm working on a flying platformer of sorts and I'm having trouble wrangling the camera. To give you a rough idea of the levels players will be navigating, have a look at this screen shot.
With my current camera system, the player stays roughly in the centre of the screen with the camera projecting forward a bit based on the player's velocity. So when the player hits a wall, half of what the camera's displaying on the screen is outside the level. How do I bound the camera so it doesn't display all of that negative space?
If my levels were rectangular, I would simply set the world bounds on the camera. Is there a solution that takes that same concept as the world bounds and applies it to a level like the one in the screen shot?
Thanks for your input :)
I'm working on a flying platformer of sorts and I'm having trouble wrangling the camera. To give you a rough idea of the levels players will be navigating, have a look at this screen shot.
With my current camera system, the player stays roughly in the centre of the screen with the camera projecting forward a bit based on the player's velocity. So when the player hits a wall, half of what the camera's displaying on the screen is outside the level. How do I bound the camera so it doesn't display all of that negative space?
If my levels were rectangular, I would simply set the world bounds on the camera. Is there a solution that takes that same concept as the world bounds and applies it to a level like the one in the screen shot?
Thanks for your input :)
About the author
www.SpryBry.com :)
#2
01/22/2010 (8:18 pm)
Have the zones overlap enough that it seems fluid
#3
I think overlapping zones may be part of the solution, but it won't solve the problem completely. Zones changes are triggered when the player enters the new bounding box. If the player is in the centre of the screen, the camera is still going to jump to the new position because half of the screen is outside of the new world bounds.
It becomes even more problematic when thinking about what happens when the player moves back and forth between two triggers. If triggers are overlapping, how do we know which one takes precedence?
Maybe I need to look at what direction the player is entering the trigger.... I feel like there's a solution here, but I can't fully grasp the logic of it....
01/24/2010 (6:31 pm)
Thanks for your response, Christopher!I think overlapping zones may be part of the solution, but it won't solve the problem completely. Zones changes are triggered when the player enters the new bounding box. If the player is in the centre of the screen, the camera is still going to jump to the new position because half of the screen is outside of the new world bounds.
It becomes even more problematic when thinking about what happens when the player moves back and forth between two triggers. If triggers are overlapping, how do we know which one takes precedence?
Maybe I need to look at what direction the player is entering the trigger.... I feel like there's a solution here, but I can't fully grasp the logic of it....
#4
That sounds like it will do the trick in theory. But I tried to add the following collision code to my camera to no avail:
Thoughts on that? :\
01/24/2010 (8:05 pm)
Because T2DSceneCamera is a T2DSceneObject, shouldn't it be possible to enable collision on the camera? Is it possible to outline my level with invisible scene objects that are set to only collide with the camera, so the camera can only move inside of my level?That sounds like it will do the trick in theory. But I tried to add the following collision code to my camera to no avail:
camera = TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>("Camera");
camera.ObjectType = TorqueObjectDatabase.Instance.GetObjectType("camera");
camera.CollisionsEnabled = true;
camera.Size = new Vector2(camera.Extent.X, camera.Extent.Y);
T2DCollisionComponent collision = new T2DCollisionComponent();
collision.InstallImage(new T2DPolyImage(camera));
camera.Components.AddComponent(collision);Thoughts on that? :\
#5
For example, setting up a bunch of nodes that the camera moves along. Then in your camera's settings. you can set the forward direction to the direction of the next node.
You also throw in a little give between nodes if it feels too on-rails for what you're aiming for, but it should allow you to customize how much negative-zone you want the player to see.
01/24/2010 (11:16 pm)
Have you considered using a path for you camera to follow?For example, setting up a bunch of nodes that the camera moves along. Then in your camera's settings. you can set the forward direction to the direction of the next node.
You also throw in a little give between nodes if it feels too on-rails for what you're aiming for, but it should allow you to customize how much negative-zone you want the player to see.
Torque Owner Bryant Drew Jones
private void ResetCameraWorldLimits(T2DSceneObject worldLimitsObject) { // Bound the camera so it doesn't look outside the edges of the world camera.CameraWorldLimitMin = new Vector2( worldLimitsObject.Position.X - (worldLimitsObject.Size.X / 2) + (camera.Extent.X / 2), worldLimitsObject.Position.Y - (worldLimitsObject.Size.Y / 2) + (camera.Extent.Y / 2)); camera.CameraWorldLimitMax = new Vector2( worldLimitsObject.Position.X + (worldLimitsObject.Size.X / 2) - (camera.Extent.X / 2), worldLimitsObject.Position.Y + (worldLimitsObject.Size.Y / 2) - (camera.Extent.Y / 2)); }This greatly reduces the amount of negative space displayed on screen, but it creates the side effect of "camera zones." Think Shadow Complex or the 2D Zelda games -- when the player moves from one trigger to the next, the camera jumps to its new position. I lose the smooth scrolling camera and a continuous space.
Any ideas on how I can keep the scrolling camera with the benefits of these triggers reigning in the camera's world bounds?