Page 1 of 1

Cool magnet script!

PostPosted: Wed Nov 26, 2014 8:01 pm
by Hblade
This script lets you apply a magnetic pull effect =)
Code: Select all
void mag(char*a1, double power, double distance_to_mag, double max_vel)
{
    Actor*a=getclone(a1);
    if(distance(x, y, a->x, a->y)<=250)
    {
        a->angle=direction(a->x, a->y, x, y);
        if(distance(x, y, a->x, a->y)>=max_vel*2)
        {
            a->directional_velocity+=power;
        } else {
            a->directional_velocity-=power;
        }
        a->directional_velocity=min(max(a->directional_velocity, 0), max_vel);
    }
    else {
        a->directional_velocity=0;
         }
    if(distance(x, y, a->x, a->y)<=5)
    {
        a->directional_velocity=.05;
    }
}


Usage: (In a draw actor script of the magnet-actor)
Code: Select all
mag("object_to_mag", .5, 50, 25);
mag("balls.0", 1.5, 50, 25);
mag("balls.1", 1.15, 50, 25);
mag("balls.2", 1.25, 50, 25);
mag("balls.3", 1.35, 50, 25);
mag("balls.4", 1.45, 50, 25);


How to use:
Code: Select all
mag("ACTOR_TO_PULL", speed, magnet_range, max_pull_speed);


Demo:
mag.zip
(11.42 KiB) Downloaded 118 times


Screenshot:
scrn.png

Re: Cool magnet script!

PostPosted: Wed Nov 26, 2014 8:32 pm
by digiot
Nice one, thanks !

Cheers !

Re: Cool magnet script!

PostPosted: Wed Nov 26, 2014 8:36 pm
by Hblade
hehe :D

I updated it to have a push effect now O:..

Code: Select all
#define PUSH 1
#define PULL 0

void mag(char*a1, int type, double power, double distance_to_mag, double max_vel)
{
    Actor*a=getclone(a1);
    if(distance(x, y, a->x, a->y)<=250)
    {
        switch(type)
        {
            case 0:
            a->angle=direction(a->x, a->y, x, y);
            break;
            case 1:
            a->angle=direction(-a->x, -a->y, -x, -y);
            break;
        }
        if(distance(x, y, a->x, a->y)>=max_vel*2)
        {
            a->directional_velocity+=power;
        } else {
            a->directional_velocity-=power;
        }
        a->directional_velocity=min(max(a->directional_velocity, 0), max_vel);
    }
    else {
        a->directional_velocity=0;
         }
    if(distance(x, y, a->x, a->y)<=5)
    {
        a->directional_velocity=.05;
    }
}


New usage:
mag("object_to_mag", PUSH, .5, 50, 25);

You can either have PUSH or PULL :D

Re: Cool magnet script!

PostPosted: Wed Nov 26, 2014 9:56 pm
by MrJolteon
Cool.

Re: Cool magnet script!

PostPosted: Wed Nov 26, 2014 10:06 pm
by digiot
I hope, Sky also has thrown out that terror of editor...

Maybe, adding a switch for push or pull would be funny !

Cheers !

Re: Cool magnet script!

PostPosted: Wed Nov 26, 2014 10:38 pm
by lcl
digiot wrote:I hope, Sky also has thrown out that terror of editor...

What do you mean?

Re: Cool magnet script!

PostPosted: Wed Nov 26, 2014 11:08 pm
by digiot
@ Lcl : I just had a horrible contact with GEs editor after a while, shocking !
And I hope, Sky has at least pimped it a little !

Here is my bloody hack to switch between pushing and pulling, just press
p, and it will change.

Cheers !

Re: Cool magnet script!

PostPosted: Fri Nov 28, 2014 9:12 am
by DjVan
Hblade (somewhere) wrote:At the moment, one thing I can think of would be to create a boss made of multiple parts.


this magnet demo might do it as well..
i can't think of the numbers of things i can do with this 8)

Re: Cool magnet script!

PostPosted: Fri Nov 28, 2014 7:30 pm
by Hblade
nice :D

Re: Cool magnet script!

PostPosted: Fri Nov 28, 2014 10:39 pm
by Zivouhr
Thanks HBlade. Sounds cool.