Hit Boxes - MichelVGameMaker/HitBoxes_gml GitHub Wiki

Parameters for hitbox_create:

parameter default details
x no default x coordinate. mandatory.
y no default y coordinate. mandatory.
sprite_index no default sprite - mask is used to detect collision. mandatory.
owner calling instance owning instance.
follow true if true, the Hit Box will follow owning instance's position, angle and scales.
damages no default number of health points lost.
can_hit_obj _HITBOX_DEFAULT_HURTABLE objects that can be hit (objects and all their children because we use parenting).
properties {} struct of custom data you want to pass to the hurt_func.
hurt_func undefined custom hurt function
hit_func undefined custom hit function, if you want to separate instructions.
timer -1 if >0, used as a destroy alarm, in steps
destroy_on_end false if true, Hit Box destroy on animation end.
visible true if false, Hit Box is invisible.
o_manager no default you can specify your own controller if you do not want to use the native one.

Associated Getters

  • is_active get the active state. Destroyed HitBox are considere inacative.
  • is_paused get the paused state.
  • get_owner get the owning instance
  • get_sprite_index get the sprite_index.
  • get_image_index get the image_index.
  • get_image_xscale get the image_xscale.
  • get_image_yscale get the image_yscale.
  • get_image_angle get the image_angle.
  • get_image_speed get the image_speed.
  • get_image_alpha get the image_alpha.
  • get_image_blend get the image_blend.
  • get_visible get the visibility.

Associated Setters

  • set_paused (_bool = true) set the paused state. When paused, Hit Box is visible (drawn) but does not process its instructions (moves, animates and hurts).
  • set_hurting (_hurting) set the hurting state. When disable, Hit Box moves and hit (hit_func) but does not hurt (hurt_func).
  • set_speed_x (_vel) set the horizontal speed. Ignored if follow_position is enabled.
  • set_speed_y (_vel) set the vertical speed. Ignored if follow_position is enabled.
  • set_owner (_owner, _do_offset) set the owner. If _do_offset is true, the position offset is updated.
  • set_mono_hurt (_mono) when true, the rehurt_timing is set to infinity.
  • set_rehurt_timing (_timing) set the required elapsed time (in steps) for the Hit Box to hurt the same entity twice.
  • set_follow_angle (_follow) set the follow behavior, if true Hit Boxes will mimic owning intance's shape attributes: scales and angles.
  • set_follow_position (_follow) set the follow behavior, if true Hit Boxes will follow the owning intance. The relative position of the hitbox to the owner (upon creation) is kept while following.
  • set_coll_accuracy (_accuracy) set the collision accuracy for moving Hit Boxes.
  • set_collider (_collider) set the colliding instance that will disable the Hit Box.
  • set_destroy_on_timer (_timer) when >0, Hit Box is destroyed after this time (in steps).
  • set_destroy_on_end (_destroy) when true, Hit Box is destroyed on animation end.
  • set_destroy_on_hit (_destroy) not implemented
  • set_property (_name, _value) set a specific property into the properties struct.
  • set_damages (_damages) set the damage attribute.
  • set_hurt_function (_hurt_function) set the hurt function(), it is passed as an argument to the instance's method called by the hit instance. hurt(damages, owner, properties, __hurt_func)
  • set_hit_function (_hit_function) set the hit function(), it is called with the id of the hit instance as argument hit_func(hit_id).
  • set_collide_function (_col_function) not implemented
  • set_can_hit_object (_can_hit) set the objects that can be hit. Uses an array of object index.
  • static set_sprite_index (_asset) set the sprite_index, used for collision detection.
  • static set_image_index (_frame) set the image_index, used for collision detection.
  • static set_image_xscale (_xscale) set the image_xscale, used for collision detection.
  • static set_image_yscale (_yscale) set the image_yscale, used for collision detection.
  • static set_image_angle (_angle) set the image_angle, used for collision detection.
  • static set_image_speed (_speed) set the image_speed, used for collision detection.
  • static set_image_alpha (_alpha) set the image_alpha, used for collision detection.
  • static set_image_blend (_blend) set the image_blend, used for collision detection.
  • static set_visible (_visible) set the visibility.

Additional Hit Box details:

You also can set some key parameters through setters methods:

  • image_xscale, _image_yscale, image_angle. The sprite is used to detect collision, so angle and scales are important. Please note that if follow is enable, those variables will be overiddent each step.
  • collider: collider can be specified by Hit Box. If the line from the owning intance's origin to the hitbox's origin goes through a collider, the entity is not hurt.
  • follow position: the Hit Box will follow the owning intance: x, y coordinates. The relative position of the hitbox to the owner (upon creation) is kept while following.
  • Follow angle: the Hit Box will mimic the owning intance's shape attributes: scales and angles.
  • hurting: You will likely want to customize what happen when hurting an instance. You can do that in the Hit Bbox library if the hurt behavior is the same for all your Hit Boxes (reducing health points for instance). You can also add Hit Box specific features through call back functions hurt_func and hit_func.
  • destruction: can be triggered on animation_end (if set to true) or after a timer (if timer is > 0) (I would advise to choose between the two and not let hitbox indefinitively alive).
  • accuracy: Hit Boxes hurt entities over their movements with a precision step of 8 pixels, you can adjust that if needed with the coll_accuracy variable.

    Please note it is the Hit Box that hurts the entity when moving. It is ok to have quickly moving Hit Boxes. But it is not designed to cover quickly moving target entities going through the Hit Box If an entity is moving quickly enough to go through the Hit Box (such as it is not colliding before movement and not colliding after movement) it will not trigger.

  • image_alpha, image_blend, image_speed variables can also be managed through setters.