Making a Smooth Following Camera

24

Stats

35,400 visits, 52,582 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Ok, this tutorial is about making a camera follow the player smoothly.

Exemple: http://militia.com.br/example1

First

You need to create your player, I'll not explain it here, you can find in Beginner's Guide how to starting using Construct 2.

Creating the Camera

Ok, after you create your player, create a blank sprite, rename it to "camera", this will be your camera.

It preferable to put the camera close to your character, or when you start the game the camera will move to the character if is too far.

But you can use this position to make a entrance for the game, for example you can put your camera in the sky, and when the game start the camera will move to your player position.

Behaviors

Add a ScrollTo behavior for your camera.

Event Sheet

Create an event Add Event>System>Every Tick and create an action Camera>Set Position

X: lerp(Self.X, Player.X, 0.03)

Y: lerp(Self.Y, Player.Y-150, 0.03)

Explanation

The magic here is the expression "lerp", when you use it, you need to put 3 values, the first one is the initial position, the second one is the final position, and the third one is the time will take to run between initial and final position.

So Self.X is the current position from the camera, and Player.X is the current position from the player.

The 0.03 can be any number, if you want your camera smoother you can decrease the number or vice versa.

For the Player.Y I inserted a "-150" because your character will be always in the middle of the screen, and in this case was better for the player to be in the bottom of the screen.

  • 18 Comments

  • Order by
Want to leave a comment? Login or Register an account!