Friday 3 May 2013

SCRIPT: pressure_wave


Here is a script you can use in the GMS physics engine, or when you are making a game with physics and want to create a cool pressure wave effect.
As we all know pressure waves are invisible, but has force which is acted out on other particles or objects in a world. In this case our game world. My game world I used this for was a simple space game, and when an explosion erupts with a visual particles effect I added this pressure wave by creating many invisible solid objects that shoots out from the middle of the explosion in a circle which will then interact with other asteroids and space ships giving it a realistic pressure wave push back effect.

For this script you require an object (oExplode_part)  that will be set to visible=off (invisible), I used a small sphere, which is set to solid with physics enabled and allow it to have collisions with the objects you want to be affected.

You can then call this script:
pressure_wave(oExplode_part);

in the DESTROY event of any object that is destroyed as an explosion and it will shoot out these invisible balls against all other objects in the area...

SCRIPT: pressure_wave

{
    var i, dims, force, ang, sz;
    //oExplode_part = argument0;
    sz=sprite_width;
    force = 20;
    //dim is the dimension of explosion wave
    dims = 50; //number of particles and directions each must travel to make physics wave

    repeat(dims)
    {
        ang=random(360);
        with (instance_create(x+lengthdir_x(sz/2,ang),y+lengthdir_y(sz/2,ang),oExplode_part))
        {
            //Apply an impulse based on a random vector
            physics_apply_impulse(x,y,force*(-sz+random(sz*2)),force*(-sz+random(sz*2)));
        }
    }
}

GameMaker Tutorials

Hi Friend,
and fellow GM developer.
I decided I will now and again add some tutorials or just brief descriptions with Game Maker Language (GML) scripts to my blog for your perusal.

Now that I added the LABEL keyword cloud to my blog, you can easily find similar topics of discussion on this blog. So I will add 2 LABELs to help you find TUTORIALS and GML SCRIPTS as I post these.

Look out I will start it with a simple script in my next post on how to make a fancy pressure wave effect during say an explosion when you use the box2d physics engine now incorporated in the new GMS.

Feel free to comment with tutorial requests here, and when I have time I just might just develop some of them for you here.