• Create Account

## Camera movement

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Hachaso77  Members

231
Like
0Likes
Like

Posted 19 February 2013 - 01:26 PM

Hi!

I'm trying to learn how to automatically animate the camera movement. I want to add an effect where the camera animates into the scene before the actual game starts. How is this done smoothly ?

Any examples?

Thanks

### #2Jutaris  Members

485
Like
0Likes
Like

Posted 19 February 2013 - 02:43 PM

I'm guessing that by animation you mean translation/rotation (i.e. moving the camera about) over time.

Really it sort of depends on how complicated you want the "animation" to be, but ultimately should be no different than moving any other object around. Each frame move/rotate the camera toward it's target.

Do you have some more details as to what your trying to accomplish?

• A Simple pan/rotate from A/B/C to D/E/F
• A series of translations/rotations
• Orbiting around a point
• Some combination of movement

Basic Flying Rules:Try to stay in the middle of the air. Do not go near the edges of it. The edges of the air can be recognized by the appearance of ground, buildings, sea, trees and interstellar space. It is much more difficult to fly there.

Come join us for some friendly game dev discussions over in XNA Chat!

### #3Hachaso77  Members

231
Like
0Likes
Like

Posted 19 February 2013 - 05:20 PM

I'm really new at this.

I would like to move and rotate the camera from a starting point to an ending point.

Something of a zoom effect. First the object is zoomed out and then the camera zooms in and rotates a little around the object to finally stop.

### #4HappyCoder  Members

4741
Like
2Likes
Like

Posted 19 February 2013 - 09:09 PM

You could define different keyframes and interpolate between them. Each keyframe representing a position and rotation at a given point in time.

To interpolate between two points you simply use

x = a * (1 - t) + b * t

where a is your stating point, b is the ending point, and t is a value between 0 and 1. You could then keep track of how much time has passed and calculate t with timePassed / animationDuration. Once time passed is bigger than animationDuration, you end the animation and continue the camera normally.

How do you represent camera rotation? If you using euler angles you could interpolate the angles as seen above and should get a good result.

Also, a trick I have found that works really well for player or camera control state is using the state pattern. It works by implementing the differnt control logic states in separate classes, then you simply have a variable in the camera that you assign to change the camera control state. So for example
class CameraControlState
{
abstract void update(Camera camera, double dt);
}

class FollowCameraControlState extends CameraControlState
{
void update(Camera camera, double dt)
{
}
}

class AnimationCameraControlState extends CameraControlState
{
void update(Camera camera, double dt)
{
// logic for animating camera
}
}

class Camera
{
CameraControlState controlState;

void update(double dt)
{
controlState.update(this, dt);
}
}

// then to use it somewhere in the code
Camera camera = new Camera();
camera.setControlState(new FollowCameraControlState(cameraTarget));

// then to start a cutscene
camera.setControlState(new AnimationCameraControlState(animationKeyframes));


Implementing that may be an overkill for you current project but I am throwing it out there for consideration. Doing the camera (and player) control like this makes it extremely flexible. You can add a first person view, a fixed camera, a top down camera, a follow camera, and any other idea you may have easily. Just add another class, you don't need to touch any of the camera code and you don't end up with monstrous switch statements everywhere in your code that are difficult to maintain.

Or a quick and dirty alternative to animating your camera could be to only allow your camera to move and rotate at a limited velocity and then start the camera far away and facing another direction.

Edited by HappyCoder, 19 February 2013 - 09:10 PM.

My current game project Platform RPG

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.