How do I find distance between two same type objects created in realtime?

0 favourites
  • 6 posts
From the Asset Store
a real time multiplayer fighting game template for your projects
  • Hi Friends,

    Need a help. In my game, objects a and b (of same type) are created.

    How can I find distance between the two objects each time so that when they are closer than 50 px they will blast. (I am using object.IID instead of object.UID)

    Regards,

    Jatin

  • distance(sprite(id1).x,sprite(id1).y,sprite(id2).x,sprite(id2).y)

  • distance(sprite(id1).x,sprite(id1).y,sprite(id2).x,sprite(id2).y)

    Hi Friend,

    I tried above solution but it not taking the function.

    My code is below.

    distance(Dot.IID(63).X,Dot.IID(63).Y,Dot.IID(67).X,Dot.IID(67).Y)

    DOT is my sprite name and for ID im taking IID.

    Regards,

    Jatin

  • distance(sprite(id1).x,sprite(id1).y,sprite(id2).x,sprite(id2).y)

    How you assigning id1 etc to your sprites?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • These id1,id2,etc.. are actually IIDs. If you only have 2 instances of the object on your layout, their IIDs will be 0 and 1. So you can use:

    distance(Sprite(0).x, Sprite(0).y, Sprite(1).x, Sprite(1).y)

    .

    If you have many instances and need to know the distance between any two, you'll need to find their IIDs first.

    Alternatively, you can create a family with this sprite and do this:

    Pick Sprite instance
    Pick Family instance
     if distance(Sprite.x, Sprite.y, Family.x, Family.y) ....
    
  • These id1,id2,etc.. are actually IIDs. If you only have 2 instances of the object on your layout, their IIDs will be 0 and 1. So you can use:

    distance(Sprite(0).x, Sprite(0).y, Sprite(1).x, Sprite(1).y)

    .

    If you have many instances and need to know the distance between any two, you'll need to find their IIDs first.

    Alternatively, you can create a family with this sprite and do this:

    > Pick Sprite instance
    Pick Family instance
    if distance(Sprite.x, Sprite.y, Family.x, Family.y) ....
    

    Thanks DOP, this way worked for me. Now I can calculate distance between two points now.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)