Custom Camera Movement for Dummies
Author: | Ray Nothnagel
|
Submitted: | 16th February, 2003
|
Views: | 5703
| Rated: |
|
|
This was requested by someone and I've done it in many games, so I decided to share the knowledge.
I - BASICS
First of all, this requires TGF or better (Knp does not support scrolling).
If you want to do any custom camera movement, NEVER use "Center Playfield on [Player Object]", which is what most people normally do. Instead make a camera Active object (which should be set invisible at the start of the level) and center the playfield on that.
II - SMOOTH MOVES
Using this technique, one can:
A) Look at MEEEEeeeee.... - Just because you control the lead character doesn't mean he/she should always be at the dead center of the screen. Perhaps that convoy you're guarding should be looked at, or before a level starts the Camera object can be set to follow a path that overviews the level. Or, put the camera, say, directly between the player and that reactor getting to explode by setting the X and Y position of the Camera object to the average of the Player and the BurningReactor objects' X and Y positions, respectively. (i.e. X(Player)/2+X(BurningReactor)/2 )
B) Smooth camera movement 1 - give the Camera object Bouncing Ball movement, and have it "Always" "Look in direction of [Player]". Also, to prevent shaking put in two more events:
"Camera overlapping Player".... Camera-> "Movement->Stop"
and the opposite, negating the condition and starting the movement.
One problem with this is that the camera jerks when you move, particularly when the Camera's movement has a high speed - don't set it any higher than 20.
C) Smooth camera movement 2 - keep the Camera object as Static movement. Add the following event:
"Always"....
"Camera->Position->Set X Coordinate" to "X Pos(Camera)/2 + X Pos(Player)/2"
"Camera->Position->Set Y Coordinate" to "Y Pos(Camera)/2 + Y Pos(Player)/2"
What this does is take the Average formula (that is (x1 + x2)/2 ) and apply the distributive property, so that every frame the camera effectively splits the distance between it and the player.
Initially, you may say this method does nothing - and with slow-moving characters, you'd be right. However, when used with a fast-scrolling game it can make things that much more exciting. Sega's Sonic games(Genesis), for example, use this to great effect, causing the view to trail Sonic slightly, and at very high speeds perhaps lose him completely, giving the effect of a cameraman who can't quite keep up.
It's also important in the advanced technique I'll describe in the next section.
III - ADVANCED TECHNIQUES
Combine A and C above to create a dynamic, exciting, smooth camera. (Note that this requires two camera objects) The first should be set as the camera in part A, freely moving around. the second should be the movement from part C, except that instead of tracking the player, it tracks the first Camera object.
Where might this be useful? Say you were making a game where, by backing against a wall, you could get a peek ahead a bit farther than normal, a la Metal Gear Solid. When your character is against a wall to the right, you could:
CameraA-Set Position to (160,0) relative to Player
And do the same for the other directions. Voila!
You may ask how you know which direction the player is hitting the background at. The easiest method is to simply get the direction of the Player object. Combined with a "Player is overlapping the background" condition, it should work fine.
That's all for this time. See ya sometime soon!
StarManta
|
|
|