Sonic. Making a smooth camera in Simple Sonic Worlds


In this tutorial, you will learn how to create a smooth camera. A smooth camera, not attached to the player, it follows him with a certain delay. But, before creating a smooth camera, let's learn how to create a regular .

Create a simple camera.

First things first, let's get rid of the usual camera. To do this, de-activate the group [CCS] Classic Camera System.

Now the code in the [CCS] Classic Camera Systemgroup will not run. At launch, we see that the camera is bigger, does not follow the player.

Next, let's make sure that our camera(frame) follows the player. To do this, in always event, add action (Action) scrolling, relative to the position of the player.

The result was the following:

Now, the camera will follow the player always. And that's a problem,because we don't need the camera to follow the player after death (the player falls under the floor).

To fix this bug,you need to check whether the player died or not.

If the player dies, then in the object Player_MovementValues,the Actionvariable becomes equal to 9 (because, this is how the engine works). That is, we only need to move the camera if Action is not 9 (the player is not dead).

Done, now, the camera does not pursue the player until his death. With the basics figured out, moving on to creating a smooth camera

Create a smooth camera

Create an active object, it will be our camera. Place it anywhere.

And rewrite the following script.

In the event (event) Start of Frame,I put the camera in the place where the player is. And turned off the classic camera.

The logic of the smooth camera is in the Always event. There, I move the camera position using the lerp function, let's analyze it in detail.

What is lerp?

lerp is short for Linear Interpolate,or linear interpolation. In practice, this function makes the movement smoother.

The syntax of the lerpfunction is as follows:

float lerp(from, to, percentage)
  • from – initial value
  • to – final value
  • percentage – the percentage by which will increase from, relative to. That is from, in this case 0%, and to will be 100%.

Here is an example of using lerp.

lerp(10, 20, 0.5)

lerp will return the value of 15,because we have increased the number 10,by 50% (0.5), relative to the number 20. In our case, 20 is 100%and 10 is 0%.

By the way, the code of the lerpfunction , looks like this.

float lerp(float from, float to, float percentage)
  return from + percentage * (to - from);

We continue to disassemble the camera.

Unfortunately, clickteam does not support functions (it does not even have a programming language). Therefore, it is necessary to equate the formula.

from + percentage * (to - from)

To the X and Y coordinates of the camera.

In this formula, we have indicated:

  • from – camera position.
  • to – player's position.
  • percentage – 0.1 (10%)

Now, the object of the camera, smoothly follows the player.

If the player has not died, then set the frame in place of the created camera object. Now, let's run.

Everything works. It remains to make the camera object invisible.

Final result.

Пожалуйста отключи блокировщик рекламы, или внеси сайт в белый список!

Please disable your adblocker or whitelist this site!