[CLOSED] Make Sprites move to nearest imagepoint.

0 favourites
From the Asset Store
This is a code so you can see the same skin on all screens (peers). Each peer gets a skin, in addition to 4 directions t
  • I got a sprite lets call it "Swarm"

    "Swarm" has a total of 9 imagepoints.

    • 0=Origin (NOT important)
    • 1=Node1
    • 2=Node2
    • 3=Node3
    • ..etc etc etc

    Before proceeding - this is a spaceship, and the way its gonna work (in its race) is that these ship can group, and thereby become a swarm.

    QUESTION/REQUEST

    How done one make a sprite do the following.

    -Calculate which imagepoint is closest to Swarm - of another Swarm?

    -Calculate whic imagepoint IT has closest to the other imagepoint?

    -"Connects" the two Swarm´s at thoese imagepoints.

    I hope some of you have the time/brain and desire to help me out a little

    Cheers.

  • Been giving it some thought ... but ...

    The imagepoints are not making it any easier.

    In theory, you would have to loop through each object, in the loop, loop through its nodes (save obj.imagepointx(loopindex), obj.imagepointy(loopindex) ) , looping through each other object, looping through their nodes: compare val closest > distance(saved.X,saved.Y,obj.imagepointx(loopindex),obj.imagepointy(loopindex) : set val closest distance(saved.X,saved.Y,obj.imagepointx(loopindex),obj.imagepointy(loopindex)

    Not friendly on performance I think.

    You could perhaps spawn and pin invisible images on the nodes, and use something like pick closest.

  • lennaert

    Thank you for your reply, but i simply lack the understanding in which to do such "complex" things.

    So for now im trying to do (as you also surgested) making invisible images on the nodes.

    But also going another route, when i would simply increase the size of the ship, when they connect and decrease when they swarm.

  • Like lennaert already said, you could do a nested loop and check all image points of swarm 1 against all image points of swarm 2 with the distance expression. The nested loop could have 3 local variables (imagepointswarm1, imagepointswarm2, distance) and when the distance becomes smalled than the previously stored value for distance it just saves the current index for imagepoint 1 and 2.

    I don't know how your swarms look, if they are very regularly shaped (example: cubes), it should be possible to predetermine which image point is nearest (or at least reduce the possibilities you have to go through) depending of the difference in x and y (their centers) and angle, as long as they are not overlapping.

    You could perhaps spawn and pin invisible images on the nodes, and use something like pick closest.

    And how would that be less resource intensive? ^^ Not saying it isn't an option, if the usere here is not well versed in programming logic.

  • Not sure if i get it right, but you could on a function call make an array for each imagepoint which contains the distance between that imagepoint and the closest ones, then sort this array based on the values. When sorted you can get the lowest value and connect to that one... shouldnt be too heavy on performance if you can narrow down to first checking which "swarm is closest"..... so, in theory. 1 check which swarm is closest. 2 populate an array with the distances of the imagepoints from swarm A and B. 3 sort the array to get the closest distance. 4. connect.... something like that.

  • mindfaQ

    tunepunk

    Thanks for you reply´s. I will keep trying.

    But i think i need to study and learn much more about C2 and programming in general before getting back to this. Its a bit too complex compared to my actual skills ^^ I understand the logic but fail at implementing it.

  • > You could perhaps spawn and pin invisible images on the nodes, and use something like pick closest.

    >

    And how would that be less resource intensive? ^^ Not saying it isn't an option, if the usere here is not well versed in programming logic.

    That depends really ... as the loop would merely consist of 1 for each going through the node sprites,

    No idea how that pans out in performance with nested loops verses the pin node images ... would have to try.

    But the approach ... is many times more easily to apply, with more variation options.

  • So i played around with the idea of having "hidden" sprites, and use them as connect tools. It sorta works.

    BUT when i connect with another "Swarm" i can for some reason move them all around, this also apply´s when i make a "AI" move them them around.

    Capx

    The ImagePoint Connect Project

    But its very heavy on preformance when i put 10 "Swarm´s" on the screen. *sigh*

  • I got some to work, hope it helps:

    demo

    capx

  • lennaert

    Just had a quick look at it - seek to work better then what i was able to come up with - thank you.

    I will work more on it when i have the needed time.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • > That depends really ... as the loop would merely consist of 1 for each going through the node sprites,

    >

    > No idea how that pans out in performance with nested loops verses the pin node images ... would have to try.

    >

    > But the approach ... is many times more easily to apply, with more variation options.

    >

    The way I see it with the nested loop you would only do the calculations of distance, while with the pinning, you would do the pinning (one time effort), but more importantly carry around those invisible objects for no (computational) reason.

  • >

    > > That depends really ... as the loop would merely consist of 1 for each going through the node sprites,

    > >

    > > No idea how that pans out in performance with nested loops verses the pin node images ... would have to try.

    > >

    > > But the approach ... is many times more easily to apply, with more variation options.

    > >

    >

    The way I see it with the nested loop you would only do the calculations of distance, while with the pinning, you would do the pinning (one time effort), but more importantly carry around those invisible objects for no (computational) reason.

    Very true.

    Implementation wise, I would guess the differ comes to how often it needed to be executed.

    Every tick ... I'm thinking the pin wins if there are more then a hand full of swarms.

    '

    Every 0.5 sec, most likely the nested loop with more then a handfull of swarms. With drawback of jank like behavior. Which can be lerped out I guess ...

  • Well for statements sake, i where hoping to do this swarming with roughly 100 units, but with even a low number as low as 20-30 it kinda chokes the lifeforce out of the game ^^ im thinking i gotta find a more effectiv way, preformance wise.

  • Well for statements sake, i where hoping to do this swarming with roughly 100 units, but with even a low number as low as 20-30 it kinda chokes the lifeforce out of the game ^^ im thinking i gotta find a more effectiv way, preformance wise.

    For starters, I wouldnt want to have all 100 trying the same at the same time

    give them some delays when they want to check, preferably randomly

  • Oh ye learning curve but yeah that sounds like a logic conclusion. But guessing there is a bigger challenge, and that is to make them move as a unit, when connected. ^^

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