Raycasting

This forum is currently in read-only mode.
0 favourites
  • Hello,

    First thanks/congrats on a very nice app/engine thats easy to use and has flexible and powerful features.

    I would love to see somekind of a raycast ability where objects can determine line of sight to other objects. This would really ease up the creation of a good AI.

  • You might be able to do that with an instant-hit bullet. Just have your sentry (or whatever) fire an instant-hit bullet in front of him every cycle. If it hits the player, then your sentry "sees" him.

  • But something like a Ray object would be very handy anyways. It could be used to make lighting effects too! And a bullet is never really accurate, since then number of directions is limited.

  • I don't think directs are a problem.

    You would handle it this way:

    Always

    • Shoot bullet at player

    if the bullet hits the player, he can be seen. If it hits a wall, then there's no line of sight.

    I think it uses 360 degrees, with decimal precision, so it'll hit its target.

    You can also layer the loops, so fire a detector to test if the player can be seen, then resize it to the size of the enemy and fire again - this time to test if the enemy will actually fit.

    You can then set these as states:

    CAN SEE PLAYER = YES

    CAN WALK TO PLAYER = NO

    -Then stay where you are and shoot

    CAN SEE PLAYER = YES

    CAN WALK TO PLAYER = YES

    -Then run towards him and shoot

    CAN SEE PLAYER = NO

    -Wander aimlessly

  • mm.. guess it can be solved, even if it's going to be a whole bunch of bullets if you have a top-down shooter with 30 enemies and you want them to be vissible only if you can see them.

    Still would be nice for lighing effects.

  • A while ago I asked if effects like this could be possible in construct, and was told they were. http://www.gamedev.net/reference/articles/article2032.asp

    That example was written in java, and the author says it would work with C++ as well.

  • yeah. that's what i'm looking for. I think someone made an example of this in mmf. I can't find it though.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I agree, some sort of line of sight function would be great. It'd be nice to set parameters for the line of sight on an object's properties, and then simply have an 'object can see [object]' event to run it all. Should save on memory usage too, when oposed to shooting out tons of invisible bullets for line of sight.

    • Tom
  • In the meantime, there are ways to cut down on the processing.

    You can test how close enemies are. For instance, if you have 100 enemies in the level, but only 10 are on screen, only run an LOS test on those 10.

    Also, when doing an LOS test, you may use several detectors, but only do ONE test. So on each loop, you need to arrange the events so it moves all the detectors at once.

    That'll cut it down a lot.

  • I think it uses 360 degrees, with decimal precision, so it'll hit its target.

    True, the bullet object uses 360 degree rotation. Anyone wanting to know more about the bullet movement should check out the Ghost Shooter tutorial... the monsters in that use bullet movement. Bullet movement can do a lot of stuff that doesn't actually have anything to do with bullets.

    And I see you're using part of the clever pathfinding routine you posted on TDC <img src="{SMILIES_PATH}/icon_smile.gif" alt=":)" title="Smile" />

    As for the memory usage, just have the bullets destroy themselves when out of the screen, or on contact with an obstacle or player. Instant hit means they'll be gone in just a couple of cycles.

    I don't see how the memory usage would be all that much higher than a raycaster updating every cycle for every sentry on the screen. It would be pretty negligible. And creating a line-of-sight routine with the bullet only constitutes coding a few events, as Dines showed. If there were a dedicated raycasting object, you'd still be creating at least three events with it (shoot ray, does the ray hit, does the ray not hit), so you'd only be cutting down your events by a small handful when making a line-of-sight routine. I just don't see how cutting out that handful of events would warrant the time it would take to develop a whole new object. An object should make the event coding process easier by replacing large amounts of events, not small ones. But hey, the SDK is there for a reason, maybe someone could take a crack at it anyway.

    As for lighting effects, yeah it would be pretty useful, depending on the scope of the object. It's a pretty big leap from casting a ray to rendering a shadow.

  • MMMm <img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" /> Excellent idea with bullet movement that will do just fine for a LOS check. Stupid me to not think of that solution, thanks for the tip/suggestions all.

    I guess a ray can still be useful but most likely there are more important/urgent matters to deal with.

  • Instant hit bullet movements can calculate line of sight very well (yes it's floating-point 360 degree so it will always hit). However I think there's still place for a line of sight plugin - or perhaps movement - because even with instant hit bullets it's slightly more tricky to write a single condition like 'Player has line of sight to X'. I suppose you could add the 'Line of sight' movement (which doesnt actually move the object) but has conditions such as 'Has line of sight to object' or 'Has line of sight to X,Y'.

    As a sidenote, I was thinking of renaming 'Movements' to something like 'Addons' because of this - their scope is not limited to just moving stuff... they're very flexible <img src="{SMILIES_PATH}/icon_smile.gif" alt=":)" title="Smile" />

  • As a sidenote, I was thinking of renaming 'Movements' to something like 'Addons' because of this - their scope is not limited to just moving stuff... they're very flexible <img src="{SMILIES_PATH}/icon_smile.gif" alt=":)" title="Smile" />

    Not to mention things like Selection Box, Drag and Drop, and Wrap aren't really movements so much as functions.

    But anyway, how about "Prefabs?" "Addon" sounds a little too much like "Plugin."

  • i can't think of a good name for them yet but all of the ones mentioned so far don't really capture what they are. hmmm ... this could be tricky because they really are more than just movements and encompass so many possiblities!

  • Prefab is the best one so far, if you ask me. <img src="{SMILIES_PATH}/icon_smile.gif" alt=":)" title="Smile" />

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