Object2 can be seen by object1

Get help using Construct 2

Post » Wed Jan 11, 2012 4:23 pm

Can I somehow check if object2 can be seen by object1?
I could do something like this:
every 0.1s spawn sensor from object1, rotate it towards object2 and set sesor.speed to high value, then check if sensor overlaps object2.
But it's very expensive (for 10 objects there will be spawned 100 objects per second, after 10 secs there will be 1000 objects and so on...)
B
53
S
14
G
10
Posts: 282
Reputation: 7,578

Post » Wed Jan 11, 2012 4:59 pm

Yeah, there's definitely better ways to do it then that. Probably the best one can be seen in the "Physics - distance joint" example capx.

When you run the example, you'll notice a blue line connecting the C2 logo and the HTML5 thingy; it constantly points from the center of one to the center of the other. Copy the events that control this straight into your own game, so that the blue line connects object1 and object2. If the blue line is overlapping a solid object, or however you want it set up, that means the line of sight is blocked and object1 can't see object2. You can add in a bunch of other conditions like distance or angle to really finetune it, too.

I've used this method pretty extensively, it works great. Let me know if you need any more help with it! SullyTheStrange2012-01-11 17:00:08
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

Post » Wed Jan 11, 2012 5:22 pm

You can also check in the how do I FAQ there are several line of sight examples listed there.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795


Return to How do I....?

Who is online

Users browsing this forum: DemantDigitalArt, farfetchd83, mjj1990 and 5 guests