Objects recognizing when another object is nearby

Get help using Construct 2

Post » Fri Jul 12, 2013 2:08 am

I'm having trouble figuring out how to get an object to detect another object of the same type at an offset. Here's a test project I've set up to show my problem, hopefully I'm making some dumb and obvious mistake here.

Event page:
http://i.imgur.com/sRKfZJR.png
Layout:
http://i.imgur.com/LzvY9i9.png

So my goal here is to get each instance of the car sprite object to notice when something is in front of it so that it can react accordingly. I'm going to have a lot of these sprites in my game at once, so it'd be nice if I didn't have to compute distance between all of them each tick. I thought the overlaps on offset was perfect, but I guess not?

Another point, in my real project file, the sprites seem to react to a second object (which is why I included the 'cone' sprite) but here it doesn't seem to register it? Though if I enable the action on the event page that moves the cone, it gets detected just fine.

I've been wrestling with this for a while and I'm just not sure if I'm doing it the wrong way or what. Can someone please give me some suggestions?

Here's a link to the .capx that the pictures came from: https://www.dropbox.com/s/lrxpi6ym5niysf0/CarSelfDetection.capx
B
3
Posts: 8
Reputation: 216

Post » Fri Jul 12, 2013 2:46 am

Well, I can show you how I deal with this. It detects objects in a square shape rather than a circle, which is what you seem to be doing (i think)

Basically, if the fish is within 5 pixels (10 pixels squared for the entire area) then the event will trigger.
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

Post » Fri Jul 12, 2013 2:55 am

Right, but your DestinationX/Y are stationary. I'm looking for any car sprite that is near any other car sprite in one specific direction (Sprite.Angle in this case).
Unless I'm mistaken your solution won't solve my problem.
B
3
Posts: 8
Reputation: 216

Post » Fri Jul 12, 2013 3:28 am

I had this problem some time ago.
Here are 3 examples I've found on the forums. Should help.
https://app.box.com/s/yf102y7q0l97qvczsilz

megatronx2013-07-12 03:28:43
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
81
S
23
G
20
Posts: 1,951
Reputation: 18,129

Post » Fri Jul 12, 2013 3:56 am

[QUOTE=JumbocactuarX27] Right, but your DestinationX/Y are stationary. I'm looking for any car sprite that is near any other car sprite in one specific direction (Sprite.Angle in this case).
Unless I'm mistaken your solution won't solve my problem.[/QUOTE]
No, I use this same thing with Player.X and Y. It doesn't have to be stationary at all.

One other way you can do it is to pin a invisible sprite to the car and when that sprite collides with an object, register the detection (think of it as "line of sight" detection)
B
10
S
3
G
3
Posts: 234
Reputation: 3,467

Post » Fri Jul 12, 2013 2:35 pm

[QUOTE=megatronx] I had this problem some time ago.
Here are 3 examples I've found on the forums. Should help.
https://app.box.com/s/yf102y7q0l97qvczsilz

[/QUOTE]

Thanks, I'm at work right now, but I'll check these when I get home.

[QUOTE=Sushin] No, I use this same thing with Player.X and Y. It doesn't have to be stationary at all.

One other way you can do it is to pin a invisible sprite to the car and when that sprite collides with an object, register the detection (think of it as "line of sight" detection)[/QUOTE]

I think that perhaps I have explained my problem improperly. I have a bunch of instances of the same object (in this case a car) on my layout and I want to know when one of them is in front of the other. It is not the player and there's say, 100 of them around at all times. To the best of my knowledge, I can't pin an invisible sprite to each of them (using event code) to use that to check for collisions. If I can, that would be great though. How do I pin 100 invisible sprites to 100 cars though?JumbocactuarX272013-07-12 14:40:53
B
3
Posts: 8
Reputation: 216

Post » Sun Jul 14, 2013 4:51 pm

megatronx,

I checked out those .capx files you linked me and while they were informative, they haven't led me to a solution for my problem. Although they did make me learn about Families, so that was good. Thanks.

Upon reflection, I was thinking that maybe my initial test project wasn't representative enough of what I want to accomplish, so I've replaced it with a new one which is much more in line with what I'm trying to do.

Download it here: https://www.dropbox.com/s/lrxpi6ym5niysf0/CarSelfDetection.capx

If you can't download it, here's some screenshots.
Layout (The car facing left is the one which accelerates)


Event Sheet


Basically, there's a bunch of cars and one of them starts to accelerate (instance variable crashed == false). Every tick, for each car in the layout, I check the area in front of the car and if it is not overlapping another car at offset then I accelerate. If there is a car detected then I stop. Unfortunately, as you can see if you run the project, the car does not stop.

How do I make the car stop?
B
3
Posts: 8
Reputation: 216

Post » Sun Jul 14, 2013 5:40 pm

This is best done with an invisible detector (left not-so-invisible so you can see it for this example).

CarSelfDetection_invisibledetector

Edit: Oops, didn't read the full thread. Here's one with multiple cars moving.

CarSelfDetection_invisibledetector_multiblackhornet2013-07-14 18:46:19
ImageImageImage
B
71
S
21
G
211
Posts: 3,614
Reputation: 119,147

Post » Sun Jul 14, 2013 9:40 pm

[QUOTE=blackhornet] This is best done with an invisible detector (left not-so-invisible so you can see it for this example).

http://blackhornettechnologies.com/Construct2Stuff/CarSelfDetection_invisibledetector.capx[/QUOTE]

Oh snap! Thanks Blackhornet! This is exactly what I needed.

Looking over the project you uploaded, I think my problems were that I wasn't understanding entirely how the "Pick" conditions worked and I didn't even think about using UIDs like that. I'll go read up on these features more now.

Thank you very much, again.
B
3
Posts: 8
Reputation: 216

Post » Sun Jul 14, 2013 10:15 pm

Actually you can replace the 'Create/Set position' with a Spawn, to save a step. Also the ColDetUID instance-variable on the Car isn't used and can be removed.
ImageImageImage
B
71
S
21
G
211
Posts: 3,614
Reputation: 119,147

Next

Return to How do I....?

Who is online

Users browsing this forum: Aquanex2 and 1 guest