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

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

For this #DrawABirdDay I decided to make a simple animation as if Greedy Grackle was one of the Socks from Sock Town!

Here's Greedy Grackle Sock!

#pixelart #animation

Hey, folks! It's been a while since I talked about Dead Drift, I wanted to give you folks a (not exactly) brief update!

Click below on [Read Article]!

Happy #WIPWednesday!

Are you working on a game?

Making some art?

Practicing a song?

Something else?

Tell us in the comments!

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

Happy #WIPWednesday!

Are you working on a game?

Making some art?

Practicing a song?

Something else?

Tell us in the comments!

It's OK if I repost my Jack Black Bowser drawing for the #MarioMovie quest? Some people might have missed it!

Oh, and if you don't know what this drawing is referencing, click on Read Article for the link!

Mission Complete! Yesterday I was thinking hard about Dead Drift and I had a game design breakthrough!

If you're interested in this kind of design stuff, click on [Read article] below...

#indiedev #gamedev

Happy #WIPWednesday!

Are you working on a game?

Making some art?

Practicing a song?

Something else?

Tell us in the comments!

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!