- 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:
Screenshot: