People who have visited this shit

GMS Tutorial - SlowMotion Effect

image

So.. i made this slow motion effect and someone in twitter asked me of how i made it and well... due to twitter’s 140 characters limitation i ended up wanting to make a full “tutorial“ where i can explain with more detail of how i made this effect, so... let’s begin with this

image

First of all we create an object called “objectSystem“ so we can take control of our slow motion variables, to make everything easier we make them global, so let’s add a piece of code in the create event and add this variables

global.slowMotion = false;

We will use that variable to check if we are using slow motion, this will help us later to make the “blur“ effect (not exactly blur but you get the idea)

global.timeMultiplier = 1.0;

Now this variable is what controls the movement speed of all our objects multiplying their variables with this one (1.0 = normal speed, 0.5 = half speed)

global.time = 0.0;

Right now, this isn’t that important really

image

So now in the “objectSystem“ we make another piece of code but this time on the step event in here we just increment our time variable by 1 each step, then we check if our “global.timeMultiplier” value is less than 1.0 (normal speed) that would mean that we are in slow motion so we set our “global.slowMotion“ variable to true, if not, we just set our variable to false.

This would be everything for our “objectSystem” and actually.. there’s not really a lot more, i’ll show you now how to make the “blur“ effect (actally more like a trail effect) and then how to implement this in your code

image

To make our trail effect we start by creating a object called “objectFade“ and putting this piece of code on its create event

“fadeSpeed“ will be what we substract to our image alpha until it gets to 0 and destroy it, putting more value to our “fadeSpeed“ will mean our object fading faster, i think 0.05 makes a pretty good effect.

Then after that we set our initial image_alpha, you can set at whatever value you want from 0.0 to 1.0, and again, i think that 0.50 is pretty good value for this

At the end we just set our image speed to 0.0 so we can have more control on the image index

image

Then in the same “objectFade“ we add this code into the step event, this is very simple, we just substract our fadeSpeed value to our image_alpha until it gets to 0 and when it gets to 0 we destroy the instance

Now this step is kinda of optional, but i recommend to make it since the effect will be more easy to implement on any object you want, this step is just to make this script

image

In this script we check if slow motion is happening (now this is when we use that global.slowMotion variable that we declared on the objectSystem and the time variable) then after that we check if the remainder of “global.time” and the argument5 is 0, if we put in the argument5 something like 60, it will create a fading image every second, if we put something like 3, it will create a fading image every second step of the game, i hope you get the idea.. i don’t really know how to explain modulo but trust me, i know how it works (kinda...), if you don’t understand modulo i recommend to you this video (and every other video of that channel, great tutorials of the GML basics)

Next i think is fairly simple to understand what i did i created an instance of our “objectFade” and set its image variables to custom arguments of the script so we can have more control of the trail fade image

that would be all for the slow motion system, there’s only something else left and that is how would you implement this to your game, that is really easy just multiply the velocity of your moving objects by the “global.timeMultiplier” variable

image

Here’s a little example of how could you do this and also adding the trail effect script we made, basically.. that’s everything, actually a really small ammount of code but i made this look more extensive since i wanted this to be fairly understandable (hopefully it was...)

anyway, you can ask me anything if you have some doubts about this (or anything really) also i hope this has been helpful to you!

-J

Comentarios

Entradas populares