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)));
        }
    }
}

No comments:

Post a Comment