2 Objects Visible for Each Other?

Discussion and feedback on Construct 2

» Sun Oct 23, 2011 2:58 pm

Hey,

U got an idea how to easily make an event sheet, that checks if 2 objects can "see" each other? (on 2D topview like the ghostshooter tut)

The condition is there are no solid objects crossing a straight line between them.

And maybe an area of the current (view) angle of both objects is only affected, so that if an enemy is turned around not looking at you he doesnt see u, even if he could.

B
15
S
3
G
5
Posts: 396
Reputation: 4,977

» Sun Oct 23, 2011 3:03 pm

And a similar question, I didnt find a solution before. Is there an easy way to check the distance between 2 objects, maybe in pixels?
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

» Sun Oct 23, 2011 3:13 pm

For the second question, you can use "distance()" on a "Compare Two Values" condition.

ex:
Distance(Object1.X, Object1.Y, Object2.X, Object2.Y)

As for the first one, you could solve this with bullets (sounds like a big workaround, but here goes):

- Every X milliseconds, Object1 looks at Object2 and fires a bullet. I don't remember if C2 has "instant bullet" parameter (which fires it very fast), but it has to be FAST .
- If the bullet collides with a solid, it is deleted.
- If bulltet collides with Object2: BINGO.

Hope this helps!
B
106
S
40
G
10
Posts: 456
Reputation: 13,152

» Sun Oct 23, 2011 3:14 pm

The best way to "fake" line of sight is try having a sprite like a line connecting two objects (see the "Physics - distance joint" example with C2 for a demo). Then you can check if that object overlaps any solid.

For distance, check out the 'pick nearest' condition or the 'distance' system expression.
Scirra Founder
B
355
S
208
G
71
Posts: 22,829
Reputation: 176,664

» Sun Oct 23, 2011 3:22 pm

Thank you gammabeam and Ashley. I'm gonna try this right now.
B
15
S
3
G
5
Posts: 396
Reputation: 4,977