Game
Dead Drift

1 year 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

HELLO EVERYONE! How are you doing this Monday?

Are you folks excited for this week? What are you planning to do?

I'd love to hear it in the comments!!!

MAKING YOUR CUSTOM BAR IN CONSTRUCT 3 - PART 1!

This is a simple tutorial about creating a custom bar using the native Progress Bar from Construct 3!

If you're interested in this kind of stuff, hop on and click on Read Article below! :)

#indiedev #gamedev

Fixed some nasty bugs, changed the dynamic font to Eeve Somepx's great "Hungry" font, and few things more!

Now it's time to go to sleep! See ya tomorrow!

Highrise Game Jam Reminder: In order to enter to win the Jam, your game must be created in Unity and submitted using the Highrise Studio Hub.

Learn all the deets about the jam at https://gamejolt.com/c/gamedev/highrisejam

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]!

🥳 The Highrise Game Jam is Underway! 🥳

Watch the video for tips on getting started building your first world in Highrise Studio. (Creating and submitting within Highrise Studio Hub is the only way to enter the jam!)

Learn more: https://gamejolt.com/c/gamedev/highrisejam

It's coming, folks!!! Anyone else excited???

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? A song? Something else? Tell us in the comments!

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...