Game
Dead Drift

2 years ago

CONSTRUCT TUTORIAL TIME! I wanted to make a "mini-article" on how to make the distance-based zoom control mechanic I did for Dead Drift since it's so easy!

If you're interested, click on [Read Article] below!

#indiedev #gamedev


Before we begin, a quick explanation of what's happening:

As the car distances itself from the base (the gray building at the center of the gif), the camera zooms out, to keep the base always on screen.

When the car drives back towards the base, the camera zooms in again, up to a certain point.

So -- How can we do something like this easily using Construct?

(Although this is a Construct-specific tutorial, the same principle applies to all game engines which have a camera or other similar component. If you're using another engine, you can try it!)


Layout Scale

In Construct, everything that we see on the screen happens inside a layout. A layout is like a screen or, to use jargon similar to the one used in engines such as Unity, a scene.

All layouts have a variable called Scale. The layout scale controls how small or big a layout will be shown when this scene is rendered on the screen.

image.png

When the scale is 1, the layout is drawn at a 1:1 scale. When this number is bigger than 1, the layout's pixels become bigger by that factor. For instance, if you set the scale to 2, the layout will be drawn twice as big, so it will look like you're two times closer. On the other hand, if this scale is between 0 and 1, the layout becomes "smaller" when rendered by that factor. If you set the scale to 0.25, everything on the layout will appear 4 times smaller (1/4 = 0.25).

Calculating the Scale

Since we want to zoom in or out dynamically, according to the distance between two objects, we'll need to create a Construct event.

For this event's condition, we'll want to use the Every Tick condition, which is the same to say that we'll do the event's actions every frame.

For the action, we'll use the action shown above, the System > Set layout scale action:

image.png

When writing the expression for scale value, we'll use what we've established above. The bigger the distance between two objects, the closer to zero we want this number to be.

Thankfully, there's a built-in Construct function for that. The distance function:

image.png

The distance function calculates the Euclidean distance between two points (x1, y1) and (x2, y2):

image.png

However, since we want the scale to be inversely proportional to the distance, we need to write our formula like this:

image.png

Because I want to calculate the distance between the CarBottom and the Base objects, I put their coordinates as the function's parameters.

K, on the other hand, is a Global Variable that will define how fast or slow the camera zooms out and in. If you make K = 1000, when the Car and the Base are 1000 pixels away from each other, the scale will be 1.0 (1000/1000). When they're 2000 pixels away from each other, the scale will be 0.5 (1000/2000), showing everything at half their size.

This is how the event should look like in your Event Sheet:

image.png

Min Scale

If we create the K global variable, assign it a value, and test the event we created above, we might experience an unintended side effect. If K = 1000, when the Car really close to the base, the scale can become really big. We might want to cap how big this scale gets.

One common way to control this is to say that the scale might never go over the regular 1.0 value (the 1:1 layout scale). It's simple to do that using another Construct built-in function, min. The min function simply returns the smallest of a list of values:

image.png

If we change our Set Layout Scale action to use the following expression...

image.png

...what we're saying is: "Construct, use the K/distance formula if the resulting value is smaller than 1. Otherwise, use 1."

This guarantees us that the camera will never come "too close" to the car. We can even use values other than 1, if we want the layout to be naturally zoomed out when the game is playing.


Well... that's it, folks!

If you try this, please let me know if it worked and let me see the results! I love knowing that my tutorials and tips or whatever helped you all :)

Cheers!



11 comments

Loading...

Next up

Here's what I'm thinking to celebrate the 1K followers milestone... the very first SOCK TOWN prototype!

It's heavily inspired by the Reigns game, but instead of being about being a king... it's about being the director of the "Sock Town" TV show!

HI! I'm getting close to hitting 1000 FOLLOWERS (woohooo!) and I'm thinking about doing some special things to celebrate this:

- A Fireside where we can play a drawing game together!

- A mini-game using the sock puppets!

What do you think of that?

QUICK UPDATE on the MISSIONS SYSTEM!

I have been working on this progression layer and things have been going well! Here's a video of me testing this system!

Click on Read Article for more info! :)

#gamedev #indiedev

This week's Fan Art Friday celebrates Baldi's Basics in Education and Learning! Accept the quest in your quest log to get started.

NEW UI PLANNING!

Since the beginning of this project, I've done its UI in a somewhat haphazard way. Now it's time to get some things right, so I'm planning to fix some things about its user interface.

Read more in the article by clicking on...

Inayah - Life After Gods is OUT NOW on Steam!

Celebrate the game's release by completing our quests!

You can play the demo or get the full game at https://bit.ly/steaminayah

Posting some other DEAD DRIFT EXPERIMENT GIFS. You can see "enemy trucks" (the dark rectangle thingies roving around) AND big zombies (they have 10x the HP of a regular zombie!!)

Some additional comments in the article!

#pixelart #gamedev #indiedev

A photo with Abacaxi, one of my dogs!

And, yes, we're both scraggly dudes.

@FatBombStudios is a CCC+ Studio that makes games you love but don't know about!

They're the devs behind the fast paced hide and seek game Light Bearers 2: https://bit.ly/LightBearers2

We think you SHOULD know about them so complete the quest!

MAKING YOUR CUSTOM BAR IN CONSTRUCT 3 - PART 2!

Time for Part 2 of our two-part tutorial on how to create your custom bar in Construct 3!

Click on [Read Article] below!

#gamedev #indiedev