Closest point to an unreachable position?

0 favourites
  • 4 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • Hi everyone,

    I want my ranged weapon ai to understand when to prefer following a target or just getting in range for a shot.

    My ai has two LoS behaviors, one with full height obstacles (i.e. Walls) and the other with low height obstacles (think: handrails and such), both block pathfinding but only the high one blocks sight.

    I want them to notice a low obstacle on the way to their target and approach it as close as possible in an attempt to line up a shot.

    It should work by having LOS 2 detect a collision in direct line to the target and moving as close as possible along that direct line.


    So i need a way to get the collsion point of my "raycheck" with low obstacles. Any ideas perhaps?

  • Here are a couple of ideas - if your low height obstacle sprites are relatively small, you can add a 3rd LOS with very narrow angle of sight. Rotate your AI towards the target position, then use this LOS to check for any low height obstacles in that direction. If found - move AI to that obstacle.

    Or you can do it with a loop like this:

    dist=Distance(ai.x, ai.y, target.x, target.y)
         System Pick LowObstacleSprite overlapping point (lerp(ai.x, target.x, progress/dist) , lerp(ai.y, target.y, progress/dist))
               //  point of collision with LowObstacleSprite found, you can move your AI to it
               Stop loop
               Add 5 to progress    // 5 is to minimize the number of overlapping checks for better performance. 
    This code basically moves a virtual point from AI to the target, checking if it's overlapping LowObstacleSprite every 5 pixels.
    It should have almost no impact on performance, unless you have lots and lots of AI objects and executing this code for each of them on every tick.
  • Can the LoS behavior return obstacles and their position then?

    Can' find anything on that the manual. Ideally it'd return some intersection point with the line check. If it even works like that

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • No, as far as I know, LOS behavior only checks if target object is visible or not. And it only tests the target's origin point, not its collision polygon or bounding box.

    So to find an intersection point with an obstacle, you need to use the code I posted in my previous comment.

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