GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 Re: GML Creations » UV Hijinks - Smoke and Mirrors » 2010-01-15 17:36:06

Thanks for the welcome and the replies , icuurd12b42 and Xot. icuurd12b42, I like your grid distortion technique on the GMC forums, in fact I built my own before I made this post which is very simalar to yours. The main problem with mine though is that the points always twitched when they were at their starting point. So ive stolen your technique for the movement of the points which is nice and smooth if thats okay with you:).  Heres the code i origionally used for my own grid effect.

objGrid - Create event

Expandvar i, o, gridDone, gWidth, gHeight, distX, distY, incX, incY;

gridDone = false;
gWidth = 2100;
gHeight = 1600;
pointsX = 25;
pointsY = 20;
distX = gWidth / pointsX;
distY = gHeight / pointsY;
x = 0;
y = 0;
incX = x;
incY = y;

r = 0;

for(i = 0; i < pointsY + 1; i += 1){
    for(o = 0; o < pointsX; o += 1){
    if(i == 0 || o == 0 || i == pointsY - 1 || o == pointsX - 1){
            global.rows[i, o] = instance_create(incX, incY, objPointStatic);
        }
        else{
            global.rows[i, o] = instance_create(incX, incY, objPoint);
        }
        
        incX += distX;
    }
    
    incX = 0;
    
    incY += distY;
}

gridDone = true;

objGrid - Draw event

Expandif(gridDone){
    for(i = 0; i < pointsY - 1; i += 1){
        for(o = 0; o < pointsX - 1; o += 1){
            nextPoint = global.rows[i, o + 1];
            nextRow = global.rows[i + 1, o];
            
            
            
            with(global.rows[i, o]){
                // sprGrid is a 1 pixel wide/10 pixel high sprite stretched and angled from one point/row to the next.
                
                draw_sprite_ext(sprGrid, 0, x, y, point_distance(x, y, other.nextPoint.x, other.nextPoint.y), 1, point_direction(x, y, other.nextPoint.x, other.nextPoint.y), c_white, 1);
                draw_sprite_ext(sprGrid, 0, x, y, point_distance(x, y, other.nextRow.x, other.nextRow.y), 1, point_direction(x, y, other.nextRow.x, other.nextRow.y), c_white, 1);
            }
        }
    }
}

objPoint - Create event

ExpandoriginX = x;
originY = y;
gravity = 0;
friction = 2;

objPoint - Begin step event

Expandif(instance_exists(objInfluence)){
    influence = instance_nearest(x, y, objInfluence);
    influenceCheck = point_distance(x, y, influence.x, influence.y);   
    originCheck = point_distance(x, y, originX, originY);
                
    if(influenceCheck < influence.radius && originCheck < influence.radius){
        if(influence.type == 0){
            if(influence.distEffect){
                pull = influence.strength / influenceCheck;
                
                if(pull > 10){
                    pull = 10;
                }
                
                gravity = pull;
            }
            else{
                gravity = 4;
            }

            gravity_direction = point_direction(x, y, influence.x, influence.y);
        }
        else{
            gravity_direction = point_direction(x, y, influence.x, influence.y) + 180;
            gravity = 4;
        }
    }
    else{
        gravity_direction = point_direction(x, y, originX, originY);
        gravity = 4;
    }
}
else{
    gravity_direction = point_direction(x, y, originX, originY);
    gravity = 4;
}

objInfluence - Create event

Expandvar i, lifeTime, radius, strength, tolerence, type, distEffect;

i = 0;
lifeTime = 30;
radius = 0;
strength = 0;
tolerence = 0;
type = 1;
distEffect = 0;

objInfluence - Begin step event

Expandif(lifeTime > 0){
    if(i >= lifeTime){
        instance_destroy();
    }
}

i += 1;

The main difference here is (other than your code being much cleaner and optimized) the way in which I'm drawing the texture between the points. But, while giving a much nicer effect being able to use a sprite than the default line drawing of gamemaker and eliminating texture distortion alltogether which appears with the texture/primative effect, it is slower than I would like:(. I think in the end I will have to go for the 'primative with a texture applied' method.

Oh and I know I have probably gone the long way round with this code and have way more variables and conditions than needed, but, I am new to gamemaker and game programming in general so thats my excuse:P

Edit: Rather than make a new post, I'll ask here. Is there an active IRC channel for gamemaker users? I've taken a look in the GMChat channel (forget which server it was) and it is always empty, other than what seems to be a bot.

#2 Re: GML Creations » UV Hijinks - Smoke and Mirrors » 2010-01-14 14:17:32

I'm new here, so I'll start by saying hey there!

Xot, would it be possible to use this method of distortion to create an interactive, fluid-like surface as seen in the grid effect of Geometry Wars 2? If you havn't played GW2 heres a link that shows the grid effect nicely.

Board footer

Powered by FluxBB