[SOLVED] How do I intances seek instances

Just started using Construct 2? Post your questions here

Post » Wed Apr 01, 2015 12:29 pm

Hi all :)

how simply spawn two kind of object, every for a number of instance like a variable "Random", and named for example "red" and "blue". So on the screen i suppose for example to had 5 instances "red" and maybe 9 instances "blue".

well, what i need to understand is : how is possible that every instance "red" follow the nearest (distance to them = 100 pixel) instance "blu" ?

(If instance "blu" distance is upper 100 pixel than instance "red" go to stop.)

thanks for help

code:
Image

layout:
Image

i cannot attach the link of .capx :( i do not why?
Last edited by Agrauwin on Sat May 16, 2015 11:54 am, edited 2 times in total.
B
8
S
1
Posts: 17
Reputation: 503

Post » Thu Apr 16, 2015 4:57 pm

what is your cone of view set to?

re: layout picture...which one is red#1? the one facing the blue or not facing?
B
75
S
26
G
14
Posts: 1,094
Reputation: 14,210

Post » Thu Apr 16, 2015 8:12 pm

- red pick nearest instance of blue
-- system compare values - distance(red.x,red.y,blue.x,blue.y) < 100
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Apr 25, 2015 8:38 pm

LittleStain wrote:- red pick nearest instance of blue
-- system compare values - distance(red.x,red.y,blue.x,blue.y) < 100


tnx to both, well, i've semplify the project
now i had 5 instances "red" and one "blu"

Image

blue : behaviors : DragDrop
red : behaviors : Bullett : initial speed 0

all seems work fine, but only if i created 1 instance of "blue"

if i created for example 2 instance of "blue" the projects run crazy....
i need that every reds seek the instance of blue nearest of itself :roll:
B
8
S
1
Posts: 17
Reputation: 503

Post » Sat Apr 25, 2015 9:06 pm

If I understand your problem correctly, I think I would do something like this.


-For Each 'Red'
--Pick nearest 'Blue' to 'Red'
---If Distance('Blue' to 'Red') < 100
----'Red' Set Bullet angle towards 'Blue'
----'Red' Set Bullet Speed = 50

-Else
--'Red' Set Bullet Speed = 0


I hope it makes sence and that it will be of help.
B
5
Posts: 19
Reputation: 263

Post » Tue Apr 28, 2015 11:04 pm

Eklofakka wrote: I hope it makes sence and that it will be of help.


Wonderful!!!!!!! Many thanks!!!!! Its work :D you are a genius!

Image
B
8
S
1
Posts: 17
Reputation: 503

Post » Wed Apr 29, 2015 9:06 pm

Happy to help! :)
B
5
Posts: 19
Reputation: 263


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 3 guests