How do I pick objects intersecting a line?

0 favourites
  • 14 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • I have a character aiming in any direction. I want to pick all objects intersecting a straight line from the character.

    I could use colission detection and raycaster, but the problem is that for optimization purposes I only want to turn on collision detection for objects in the bullet trajectory, just before the bullet is fired.

    Or could I pick within an angle or small cone from the player?

  • You can use line of sight with a very small cone of view, and change the angle to the bullet angle.

  • You can use line of sight with a very small cone of view, and change the angle to the bullet angle.

    Even if it returns true or false, it's not picking the obstacle, or maybe I'm doing something wrong?

  • You can fire a fake raycaster object - I do this with a few projects.

    You make a bullet object the fires *super fast* before your shot to measure targets and solids.

    It's basically an invisible bullet that fires at a hugely fast velocity - then use that data to return some info.

    ~Sol

  • You can use line of sight with a very small cone of view, and change the angle to the bullet angle.

    And also, LOS, seems to be based on collisions, so not detecting obstacles with collisions off. I need a way to pick objects in a straight line from the player, without the use of collisions.

  • newt still lightning fast on the draw...

    ~Sol

  • dl.dropboxusercontent.com/u/666516/picklinosight.capx

    Ahhhh. that seemed to work. I need to try it out, in my project. Thanks.

    I was using has line of sight to, x, y position.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • dl.dropboxusercontent.com/u/666516/picklinosight.capx

    SoldjahBoy

    We're getting closer, but i think I have to write something custom with events. Larger objects will fail to detect, or if you are close to objects. I need to detect based on the Bbox, and not the XY, so back to the drawing board, and play with events.

  • SoldjahBoy

    newt

    I managed to solve it finally.

    dtAim is the distance to the center line between two imagepoints of the player.

    if the distance to the center line is less than a certain ammount(in this case less than the obstacle widht/2, pick those objects.

    Now i'm just gonna filter out objects based on distance, and objets behind the player.

  • I usually just use a square sprite. Make it's origin be left center then with events set it's angle toward where you want it to end and the width to the distance and height to 1. Then to pick objects touching it it's just a matter of using the overlap condition.

  • R0J0hound yes yes, thats the easy way but in order to use overlap you need collisions turned on. So the hard part this time was not using collisions, because i want to turn on collisions for objects in the line of fire of the player.

    I'm Optimizing the game, so took down collision checks dramatically from approx 90 tick, by defaulting everything off, and just turning on for certain objects when needed. In this case, just before firing, and off again on hit. By only turning on colisions for objects in the line of fire, now my game runs at 1-2 colission checks per tick, mostly zero if any characters or bullets are not moving, or close enough to any obstacles.

  • Lmao looking at that formula you have there is making my eyes hurt this early in he morning. That'll teach me for trying to brain before I coffee.

    Glad you resolved it I'll check it out again once my hamster starts running.

    ~Sol

  • Lmao looking at that formula you have there is making my eyes hurt this early in he morning. That'll teach me for trying to brain before I coffee.

    Glad you resolved it I'll check it out again once my hamster starts running.

    ~Sol

    HAHAHA How's that for a hearty breakfast? I used the same formula elswhere in game to determine weather an object was on one or the other side of a line between two points, (without the 'abs'), and it worked. returns the distance to that line, very useful in many cases.

    So credit goes to R0J0hound for solving it earlier in this thread.

    https://www.scirra.com/forum/viewtopic.php?f=147&t=148922

    Awesome piece of formula.

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