Limited view from horizontal to vertical
by Ryan Jones · in Torque Game Builder · 11/30/2008 (2:12 pm) · 2 replies
Okay, maybe I'm going about this the wrong way but here's what I'm trying to do.
For my test game I'm recreating a level from Megaman 1, specifically Fireman's stage. In Megaman the camera view is always limited between certain Y values so if you're walking along the bottom of the level the camera doesn't let the player see too far down.
I've been able to copy this technique using the platformer camera behavior from your mini platformer tutorial. I created an objected, added the camera behavior to it, the object name is player, readjusted the world limits and select clamp. http://tdn.garagegames.com/wiki/TGB/Tutorials/Platformer/Camera
This works very well and horizontally I have no problems. The problem I do is when I want the camera to move from horizontal to vertical and still have a fixed view. What happens is as soon as I leave the world limit the camera doesn't move any further (like it should) but I want to have the camera with this fixed view move vertically now following the player. Then once at the top of this vertical section it would move horizontal again.
I've been trying to figure this out but I think I'm going about this the wrong way. Any help would be appreciated.
For my test game I'm recreating a level from Megaman 1, specifically Fireman's stage. In Megaman the camera view is always limited between certain Y values so if you're walking along the bottom of the level the camera doesn't let the player see too far down.
I've been able to copy this technique using the platformer camera behavior from your mini platformer tutorial. I created an objected, added the camera behavior to it, the object name is player, readjusted the world limits and select clamp. http://tdn.garagegames.com/wiki/TGB/Tutorials/Platformer/Camera
This works very well and horizontally I have no problems. The problem I do is when I want the camera to move from horizontal to vertical and still have a fixed view. What happens is as soon as I leave the world limit the camera doesn't move any further (like it should) but I want to have the camera with this fixed view move vertically now following the player. Then once at the top of this vertical section it would move horizontal again.
I've been trying to figure this out but I think I'm going about this the wrong way. Any help would be appreciated.
About the author
Creator and project manager of Lightsire Entertainment. http://www.lightsire.com
#2
Using platformerCamera the line of code that determines the view limit is:
%limit = %this.owner.getWorldLimit();
%mode = getWord(%limit, 0);
Creating two scene objects with their own world limits (one named scene01 and other named scene02) I can have the player's focus be on one or the other with a simple modification of the code above:
%limit = $currentview.getWorldLimit();
%mode = getWord(%limit, 0);
$currentview is a global variable. If I set this variable to "scene01" then it tracks that part of the level properly. If I set this variable to "scene02" then it tracks the next part of the level properly. So the problem here is having a sort of trigger that can assign a value to my variable as needed.
I need a trigger that if a player enters and leaves the trigger from the same side nothing happens. If the player enters from one side and then leaves through the other side then it activates.
I was looking through some behaviors and came across MusicTrigger. I think this has what it need I could use some help with this one. This is what I want to happen when the player enters the triggered area but nothing is happening.
Is this the trigger I am looking for or do I need something else?
01/08/2009 (1:19 pm)
Maybe I just can't picture in my head what you're trying to tell me, but I just don't think a scroller would work for me.Using platformerCamera the line of code that determines the view limit is:
%limit = %this.owner.getWorldLimit();
%mode = getWord(%limit, 0);
Creating two scene objects with their own world limits (one named scene01 and other named scene02) I can have the player's focus be on one or the other with a simple modification of the code above:
%limit = $currentview.getWorldLimit();
%mode = getWord(%limit, 0);
$currentview is a global variable. If I set this variable to "scene01" then it tracks that part of the level properly. If I set this variable to "scene02" then it tracks the next part of the level properly. So the problem here is having a sort of trigger that can assign a value to my variable as needed.
I need a trigger that if a player enters and leaves the trigger from the same side nothing happens. If the player enters from one side and then leaves through the other side then it activates.
I was looking through some behaviors and came across MusicTrigger. I think this has what it need I could use some help with this one. This is what I want to happen when the player enters the triggered area but nothing is happening.
function CameraTransitionBehavior::onAddToScene(%this, %scenegraph)
{
// Make sure we're a trigger
if (%this.Owner.getClassName() !$= "t2dTrigger")
{
error("CameraTrigger must be used with a t2dTrigger object");
return;
}
// Make sure we check events properly
%this.Owner.setEnterCallback(1);
%this.Owner.setStayCallback (0);
%this.Owner.setLeaveCallback(1);
// Ensure that the player collides with this trigger
%this.Owner.setObjectType("PlayerTrigger");
%this.Owner.setCollidesWith("None");
%this.EntryDirection = 0 SPC 0;
%this.LeaveDirection = 0 SPC 0;
}
function CameraTransitionBehavior::onEnter(%this, %theirObject)
{
// Record the entry points
%this.EnterDirection.X = 2 * (%theirObject.Position.X > %this.Owner.Position.X) - 1;
%this.EnterDirection.Y = 2 * (%theirObject.Position.Y > %this.Owner.Position.Y) - 1;
}
function CameraTransitionBehavior::onLeave(%this, %theirObject)
{
// Record the exit points
%this.LeaveDirection.X = 2 * (%theirObject.Position.X > %this.Owner.Position.X) - 1;
%this.LeaveDirection.Y = 2 * (%theirObject.Position.Y > %this.Owner.Position.Y) - 1;
// Check if we should do something
%deltaDirection = VectorSub(%this.LeaveDirection, %this.EnterDirection);
if ((%this.Axis $= "X-Axis" && %deltaDirection.X != 0) || (%this.Axis $= "Y-Axis" && %deltaDirection.Y != 0))
{
Do something.....
}
}Is this the trigger I am looking for or do I need something else?
Torque Owner Ezra
That is very similar to the platformer camera behavior, I actually used that as a starting point for what I'm talking about, but instead of using the camera view limits I mounted 4 "blocker" objects to the camera that handled collision with the Player because it suited some issues I was running into, and I was also able to enable or disable sides of the screen if needed.
As for the scroller object though, I guess you wouldn't have to have it in the upper left of the screen but I like it since it is easy to relate to the player when figuring out where the player is inrelation to the camera's viewable area.
The general idea is that instead of having the camera directly following the player, you have it follow this scroller object all the time no matter what. The scroller object has its own behaviors/states for how it can move, you can feed the player position to it if you'd like it to follow the player, or change its behavior to one that pans over a screenwidth when the player hits some object or the camera viewl imits (I believe the object collision would make more sense because you could visually design the layout of the level more accurately and divide it up into camera sections).
Say you'd like the player to always be centered horizontally, you'd be updating the scroller object by either directly setting the position or with a move to command (or probably other potential ways), giving it the player's X position - 320 (if your camera width was 640 for example), this just keeps it in sync with the upper-left corner idea, The camera would just be mounted to the scroller (either fixed or elastic), but you will want to use the mount command that converts a world position to local coordinates on the object (from what I remember, hopefully I'm not making stuff up).. so that the camera doesn't center itself on the scroller object (unless of course the scroller object is always going to be centered in view and not in a corner...)
I guess it might be odd since it seems overly complicating, but by having the camera follow a scene object that only handles the scrolling you are able to do various tricks, one being how cameras move in vertical scrolling shooters, they are fixed scrolling vertically, but the left/right movement is actually a percentage of where the player is on the overall width of the level, (for example a vertical shooter with 240 pixel screen width would likely have a 320 pixel level width), so the camera is only ever moving within 80 pixels max to the left or right, and this is tied to the player's position inside the 320 width (as a percentage).. this way you always get the responsive feel of having the camera move left or right coinciding with left or right on the joystick, always.. and you don't get the awkward start-stop feel when the camera hits the edge of the world before the player, but the player ship is still moving.
That is also a bit similar to how I assume it is done in 2d fighting games, except the scroller object is finding the midpoint vertically between the two players Y positions (for when they jump if the screen is to scroll upwards)..
Another thing you can do is the 1 screen pans, keep the scroller static until the player hits an invisible scene object which tells the scroller object to move to a position a screen widths away (while even freezing player movement and everything else like in megaman).. you could even possibly use the invisible scene object for that position, or temporarily mount the scroller to it with an offset for the nice elastic movement.
Once the scroller has reached the position it tells everything to unfreeze. The invisible scene object could even then tell itself to pop over X units to the left and swap behaviors to one which would tell the camera to pan back to the left if the player decided to walk backwards (and then reset itself over to the right again re-enabling the initial behavior... :] )
You can also do stuff where the scroller follows a path or patrols along a list of positions, secondary screen shakes etc..
Wow this is long winded and rambly, anyway hopefully that gives some ideas for handling camera scrolling, sorry that I don't have any script examples, it is mostly just variations of that tutorial though... Another thing is to think about camera width and height when laying out your level, it could be wise to be sure that it can divide evenly if you used your camera's width and height as a unit of measure... but that isn't so important though if your game constantly scrolls in one direction or is very free form / open with how the camera follows the player around.