[CLOSED] Make Sprites move to nearest imagepoint.

Get help using Construct 2

Post » Fri Jul 03, 2015 7:28 pm

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

Image

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.

Image

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

Cheers.
Last edited by CrudeWall on Sun Jul 05, 2015 5:20 pm, edited 1 time in total.
B
16
S
8
G
1
Posts: 153
Reputation: 2,549

Post » Fri Jul 03, 2015 8:56 pm

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.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Sat Jul 04, 2015 10:36 am

@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.
B
16
S
8
G
1
Posts: 153
Reputation: 2,549

Post » Sat Jul 04, 2015 11:04 am

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.


lennaert wrote: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.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Sat Jul 04, 2015 1:43 pm

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.
Follow my progress on Twitter
or in this thread Archer Devlog
B
38
S
15
G
17
Posts: 949
Reputation: 12,320

Post » Sat Jul 04, 2015 7:20 pm

@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.
B
16
S
8
G
1
Posts: 153
Reputation: 2,549

Post » Sat Jul 04, 2015 9:01 pm

mindfaQ wrote:
lennaert wrote: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.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Sun Jul 05, 2015 12:46 am

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*
B
16
S
8
G
1
Posts: 153
Reputation: 2,549

Post » Sun Jul 05, 2015 7:01 am

I got some to work, hope it helps:


demo


capx
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,562

Post » Sun Jul 05, 2015 9:08 am

@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.
B
16
S
8
G
1
Posts: 153
Reputation: 2,549

Next

Return to How do I....?

Who is online

Users browsing this forum: mindragon73 and 12 guests