GMS 2 Multiple collisions with collision line[SOLVED]

S

ShuDiZo

Guest
I'm having trouble with multiple collisions using perfect collisions. The problem that occurs with:
//Single collision but only performs the damage state once
var cc = collision_line(x, y, kx, ky, obj_elifeparent, false, true);
if (cc && can_hit == true){
cc.hp -=damage;
can_hit = false;
}

///Single collision but constantly distributes damage to the target
var cc = collision_line(x, y, kx, ky, obj_elifeparent, false, true);
if (cc){
cc.hp -=damage;
}

The problem i'm having is mostly the distribution of damage to objects via sprite mask (Non physic collision checking)

Can anyone please help/teach me how i could use arrays to save the id's of each object colliding with the line and also how i could distribute damage once. Thank you in advance.
 
Last edited by a moderator:
S

ShuDiZo

Guest
You have to turn around the logic and instead of the projectile checking for obj_elifeparent, make obj_elifeparent check for the projectile.
There is this script
www.gmlscripts.com/script/collision_line_list
That does this for you. This is with lists instead of arrays but it works the same.
Thanks for the advice, but do how do we find the x and y variables of the laser projectile? Or should if keep those variables as the x and y of the obj_elifeparent?
 

Simon Gust

Member
the arguments for x1, y2, x2, y2 are x, y, kx, ky. ->
Code:
var list = scr_collision_line_list(x, y, kx, ky, obj_elifeparent, false, false);
scoping handles that, your positions are available to all instances of obj_elifeparent as long as they are declared using var inside the script and also in the same pair of brackets or the same code block.
 
S

ShuDiZo

Guest
Maybe this guide will help you:


Miradur
Thank you, that helped a ton. I was confused when Simon Gust told me to make obj_elifeparent check for the projectile because obj_elifeparent is the enemy life parent which is the target. The laser projectile is created by the player object, therefore getting the x and y variable for the projectile from the enemy is difficult.
 
Top