• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker [SOLVED]Checking for object parent problem

mar_cuz

Member
Hi All,

I have an issue checking for object parents. Say I have a sports team, all players have the same parent, oPar_BlueTeam. I'm using point_in_triangle to check for an instance of oPar_BlueTeam to kick the ball to, it only works when one blue team player doesn't have the same parent as the rest even then it only works on one of the blue team players. I need it to work with all blue players all having the same parent.

Please help.
Thanks.
 

Simon Gust

Member
I'm guessing when you use the point_in_rectangle, the shooter passes to himself as he is the first one to be detected when there is no other player. The thing is, this function can only detect one object at a time, and if the parent is the same it will probably detect itself most of the time.
 

mar_cuz

Member
I'm guessing when you use the point_in_rectangle, the shooter passes to himself as he is the first one to be detected when there is no other player. The thing is, this function can only detect one object at a time, and if the parent is the same it will probably detect itself most of the time.
I'm not shooting when there's no other players. Say I have a defender, midfielder and attacker. I'm controlling the midfielder which does not have a parent (for testing purposes). The defender and attacker have the same parent (oPar_BlueTeam) The midfielder checks for an instance of oPar_BlueTeam with point_in_triangle to pass to. It works perfectly for passing to the defender but does not for the attacker even though they share the same parent. I need it to work when all players, including the midfielder have the same parent.
 
@Simon Gust jus by the way, o_minus says he's using point_in_triangle, not point_in_rectangle.

@o_minus Are you using with() ?

Code:
var players_in_range = ds_list_create()

with ( oPar_BlueTeam )
{
    if ( point_in_triangle(x, y, x1, y1, x2, y2, x3, y3) )
    {
         ds_list_add(players_in_range, id) 
    }
}

// Here you now need to process all the ids in the <players_in_range> ds_list and
// determine which one you want to pass to.
// Maybe you pass to closest, or the one who is more directly in front of the player etc...

ds_list_destroy(players_in_range)
 
D

dannyjenn

Guest
What exactly are you trying to do?
If you want it to make a ds_list of all blue players in the triangle, and then figure out who to pass it to from there, then I think you should go with what @IndianaBones said. However, it's probably better to create the ds_list just one time (when the game starts) and then clear it whenever you pass the ball, rather than to create it and destroy it every time you pass the ball.
 

mar_cuz

Member
@Simon Gust jus by the way, o_minus says he's using point_in_triangle, not point_in_rectangle.

@o_minus Are you using with() ?

Code:
var players_in_range = ds_list_create()

with ( oPar_BlueTeam )
{
    if ( point_in_triangle(x, y, x1, y1, x2, y2, x3, y3) )
    {
         ds_list_add(players_in_range, id)
    }
}

// Here you now need to process all the ids in the <players_in_range> ds_list and
// determine which one you want to pass to.
// Maybe you pass to closest, or the one who is more directly in front of the player etc...

ds_list_destroy(players_in_range)
No not using with(); thanks for the code I can't try it a the moment but I will after work.
 

mar_cuz

Member
I have solved the issue by using a script from gmlscripts.com: instance_find_team. I set all team mates to have a variable called team = 5; and checked for that in the triangle.

Thanks for the input from everyone.
 
Top