Wiki

Clone wiki

NuclearThroneTogether / Scripting / Objects / CustomProjectile

CustomProjectile is a special object intended for creating all sorts of projectiles or similar "impact-based" objects.

Variables

Script references for callbacks (on_) can be obtained via script_ref_create.

team

Numeric: Determines the projectile' team. Objects don't get hit by projectiles with the same team.

creator

Instance ID of object that created this projectile. This is occasionally used to apply effects based on projectile's creator.

damage

Numeric: The amount of damage that projectile deals on impact.

force

Numeric: The amount of knockback (px/frame) that projectile deals on impact.

on_step

Executed every frame in Step event.

on_begin_step

Executed every frame in Begin Step event.

on_end_step

Executed every frame in End Step event.

on_draw

If defined, overrides the default Draw event.

on_anim

Executed on Animation End (should your projectile need to change states based on this).

on_wall

If defined, will be executed when the projectile hits a wall. Otherwise hitting a wall will destroy the projectile.

on_hit

If defined, will be executed when the projectile hits something. Otherwise it'll deal damage as per damage and force variables.

on_destroy

Is called when the projectile is destroyed, from hitting an enemy or otherwise.

Examples

explosives.mod.gml

trace("Press B to shoot explosives");
#define step
with (Player) if (button_pressed(index, "horn")) {
    with (instance_create(x, y, CustomProjectile)) {
        team = other.team;
        motion_add(point_direction(x, y, mouse_x[other.index], mouse_y[other.index]), 8);
        image_angle = direction;
        sprite_index = sprBullet1;
        image_speed = 0;
        on_wall = script_ref_create(test_impact);
        on_hit = script_ref_create(test_impact);
    }
}
#define test_impact
instance_create(x, y, Explosion);
instance_destroy();

Updated