[SOLVED] collision_circle return more than one value

E

Edeyz

Guest
I am trying to draw a line from one instance to another when the mouse is on top. But if the instance running the code is after the instance in the with event it does not draw a line. How do I fix this?

Here is my code:
draw_self();
draw_set_colour(c_teal);
if mouseOnTop == true
{
with collision_circle(x,y, sprite_width * size, object_index, true, false)
{
draw_line(x,y,other.x,other.y);
}
draw_circle(x,y,((sprite_width * size) / 2) * 1.1, true);
}

Thank you
Edeyz
 
E

Edeyz

Guest
Sorry, I cant do screenshots today I get about 5Kb/s. I need to go to the library to upload a screenshot. (and they are shut now, its 3am here).
Presuming the instance order is alphabetical here is an example:

mouse is on top of objectB
{ = coalition circle extent

{ (objectA) / \ / \ not-a-line / \ / \ (objectB)------draw_line-------(objectC) } / \ / \ not-a-line / \ / \ (objectD)

The line should be drawn between B & A and B & C
But It just draws between B & C

also this is in a draw event in objectB
 

obscene

Member
Oh. So you have TWO objects in range of the circle that you want it to draw a line to, but only one is drawn?

If I understand the problem correctly, it's caused by the fact that a collision function only returns ONE value, so there could be 50 objects in the range of the circle but only one will be returned.

If that's what's going on, you can fix it one of two ways...

1) Check for a collision, store the instance in an array, move it far away (temporarily) and keep checking until there are no more collisions. Then use your array to draw the lines.

2) Use (with) to have all the other objects (that are not the same instance) check with a collision with the specific instance and draw their own lines back.
 

FrostyCat

Member
Any time you want to get all instances that match a certain condition, you need to use a with-if combination block. In this case, use id != other.id to exclude the original instance, then the same collision_circle() condition from the perspective of an instance being checked this way.
Code:
with (object_index) {
  if ((id != other.id) && (collision_circle(other.x, other.y, other.sprite_width*other.size, id, true, false) != noone)) {
    draw_line(x, y, other.x, other.y);
  }
}
 
E

Edeyz

Guest
Yes that was it, thank you.
I used your second suggestion, but got rid of the coalition check.
with object_index
{
if (distance_to_object(other) <= (sprite_width * size) + global.warpDistance)
{
draw_line(x,y,other.x,other.y);
}
}
 
Top