How do I draw the line of sight behaviour cone?

1 favourites
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • So I have a game that uses turrets, and I want to use the line of sight object to detect players, and show the line of sight cone for the player to see. However I also want it to occlude to the walls like below:

    This one was done by blending a light cone graphic with a canvas with rendered "shadows", which is very effective but very costly, especially if you are using multiple turrets.

    Any ideas for a more simpler method? Probably one that actually uses the line of sight behaviour?

  • This could be very tricky to do.

    Programming-wise, what I would do is to check for any "obstacle" insight with quad tree data structure and draw my fan polygon's points with respect to all these obstacles. This one single sentence requires a hair or two to fall off from your head while implementing.

    But in C2, this could be tough unless you can find a plugin that can address the above.

    Instead of a cone, what about a laser sight that quickly move back and forth like those retina scanner in movies instead? If done right, it could achieve similar effect like the cone with better performance. But this will still require trigonometry work to address the walls, etc in your event sheets. ...good luck.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That radar line idea sounded quite cool, so I thought I'd implement it and performance is incredible. The vision cone implementation I explained earlier used around 5% of the CPU on my desktop, which isn't much except that the radar method only uses less than 1%!

    See for yourself!

    Athough I'm thinking of if there is any way to improve the visibility of it, I was thinking of making it trail but that would add to drawing. :/

  • Although I am already amazed from both results (I can't begin to understand what are you two saying above), the example with the line is a bit misleading imho. If I saw that in a game, I would assumed that the line of sight is pinpointed and rotates back and forward, not that it actually covers the whole area of the cone.

    This 3 part series of tutorials has some interesting ideas that perhaps could prove of some value to your work

    https://www.scirra.com/tutorials/792/the-land-of-light-and-shadows-part-1

    https://www.scirra.com/tutorials/793/the-land-of-light-and-shadows-part-2

    https://www.scirra.com/tutorials/796/the-land-of-light-and-shadows-part-3

  • gamepopper nice result you got there, man. But what I would do is to make those laser move quicker to imply its importance visually. But up to you though.

    I got 60 fps on my smartphone here.

  • Yeah, the example uses a sine wave at 2 second periods, just to show that it works.

    eli0s I can see your point. I think it might work better if there was a trail effect or have more than one line displaying at a time. Just need to experiment with it.

  • Perhaps you can spawn a number of lines within the tower view cone, or randomly change the laser angle to fill the line of sight area.

    The canvas plugin can do trail effects, although it's a bit strange in its usage, I can't figure out why a small trail is being left visible in the following example.

    Example capx: http://www.eli0s.com/Tests/TowerLaser.capx (the 3 left towers aim at the mouse position)

    Canvas Plugin: https://www.scirra.com/forum/plugin-canvas_t64239

  • How does this look:

  • Thats looking preety cool so far. I wonder if you could change the color when you detect your "target"... it would give you a nice dramatic effect.

  • That's great gamepopper, great gob. The color change if on sight that Ragevortex suggests will be awesome too

  • Ragevortex That would be awesome! However the line itself is a tiled background, same with the "Eraser" object that gets the trail effect to work, so unless I apply a shader effect to both it'll be difficult.

    eli0s I think the remaining trail issue has to do with the opacity of the eraser value. I've gotten better results setting it to 10 instead of 1.

  • The thing is that the opacity of the eraser affects the time of the fade out. The greater the value the fastest it fades but with better results.

    Ideally this shouldn't happen, even with 0.01 opacity, eventually it should have fade out completely.

    I posted this as a question to R0J0hound in the Canvas Plugin topic, so hopefully he will confirm it and give some advice.

  • Maybe it just takes a while for the trail to fade completely.

  • Well, that doesn't seem to be the case. I am not sure that I get what cause the problem, but R0J0hound provided a solution.

    https://www.scirra.com/forum/plugin-canvas_t64239?start=290

    Just set the Blending of the eraser to Additive instead of Destination Out.

    Here are side to side comparisons: http://www.eli0s.com/Tests/CanvasTests/CanvasAdditiveBlend.capx

  • eli0s I'll try that when I get back home.

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