Object2 can be seen by object1

0 favourites
  • 3 posts
  • 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...)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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! <img src="smileys/smiley1.gif" border="0" align="middle" />

  • You can also check in the how do I FAQ there are several line of sight examples listed there.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)