How do I check for LOS to object hitbox?

1 favourites
  • 7 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • So I'm using the Line of Sight behavior and want to know if it is possible to check if the object is seeing the hitbox of the other object rather than a image point. Is there any way to do this, or is that how it already works, or did I just not see something?

  • You can set other imagepoints and use them, or use co-ordinates. Why is the origin not good enough though?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It works for the most part, but not always. It's not a big deal, I was just curious

  • It's actually a difficult problem to solve in general: imagine a tiny gap in a wall with a large object behind it. How do you tell if you have LOS to the large object behind the wall? You'd need to check hundreds or possibly thousands of points distributed across the large object to see if you have LOS to any of them, which is probably too costly to do for performance. So the best thing to do is probably just pick a few key parts of the object with image points and check LOS to any of those.

  • I like that kind of problem.

    One idea is a rough LOS check. Basically repeatedly pick a random point inside the collision poly a do a LOS with that. Would fail more with smaller loops if the object is obstructed but it may give a true eventually. Could be a useful approximation of vision. Anyways the main sub problem to solve would be to get a random point in a polygon.

    A second idea is to utilize raycasts. Either a uniform spread of rays in roughly the direction of the object or use a bit of random. If any of the rays hit, there is LOS. I think this one is the most doable. Not sure if the ray cast feature in c3 can be used for this but making a ray cast with events would work.

    Another idea if to calculate the view polygon from one point and check to see if that view poly overlaps an objects collision poly. May be tricky to calculate though. One approach would be to do what shadow casting does and clip away from the collision poly the shadow bits. This would give an absolute is in in Los or not check.

    Anyways just some ideas, each with their own set of sub problems to solve. Maybe some are useful.

  • I've done something similar before. The solution I settled with was to set imagepoints at every corner of a los blocker, the cast rays immediately before and after every corner in range. Then see if any rays collide with the object in question. The key is that you're casting rays at the obstacle corners, not the target object directly.

    Depending on the sizes (and distance) of the origin and target objects, you can further cull the rays cast by only checking the corners in a certain direction, within a set range of angles from the angle between origin and target.

    It ended up much more accurate and higher resolution with less rays cast than trying to cast rays every x degrees in all directions, and more reliable than casting rays at the object.

    An alternate solution could be to cast a fan of rays towards the target object, wide enough to envelop the object. If the target is a fairly square or round shape you could set the bounds of the fan based on the distance and width/height of the target, then cast x amount of rays based on the desired resolution (or by distance, since you probably want higher resolution the farther away the target is).

    Edit 3: For further (significant) optimization, first check to see if the target origin is in los directly before casting any additional rays at all.

  • I like the idea to limit the range to try casting rays.

    Here's the current idea. We find the bounding circle of the target object and only shoot a random ray that would hit that circle. It tries at most 20 times to find a ray that hits the object. Seems to work well enough, but the more obscured the object is the less likely it succeeds.

    dropbox.com/s/w8f937c8y0edfyh/LOS_Object.capx

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