[Plugin] jcw_trace (raycast)

0 favourites
From the Asset Store
The I18N (Translation) is a Construct plugin created to translate text in game.
  • Traces (or raycasts, if you prefer) are line intersection tests which can be performed by every major game engine, and are very useful for getting information about an object's environment. However, detailed line traces are something that Construct 2 has been lacking. I've seen a few attempts at line traces done in events, however, they weren't very pleasant to use.

    So, to rectify this, I started on a trace plugin, based in part on the line-of-sight behavior. Just like the line-of-sight behavior, you can filter the trace to either solids or a custom list of object types, and you can tell it whether to use collision cells or not. It currently only does line traces, with hull traces planned later.

    The plugin has a couple of actions to manage the custom object type list, and 1 action for performing a line trace. The result data from the line trace is stored in the plugin object, and can be accessed via expressions. This currently includes hit position, the normal angle of the line it hit, and the UID of the object that line belongs to. The trace result persists until the next line trace is performed.

    Last updated: 2016-11-25 9:27 PM PST

    Download

    Preview (Drag the endpoints around, and observe the results.)

    .capx

    DISCLAIMER:

    The plugin provided here is just the first thing I made that worked well enough for my purposes. No real attempts at optimization have been made, other than copying some design patterns I saw in the construct 2 runtime. Using it in a large project is not recommended at this time.

    Now, I have a question for ASHLEY. Why is this not default functionality? Traces are too useful for a game engine to not have.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Great plugin!

    It is better then my light behavior, since my behavior could not get normal vector well.

  • Feature request:

    Since there has input vector and normal vector, how about adding another expression to get reflection vector?

  • rexrainbow

    What formula does the bullet behavior use?

  • newt

    startangle = inputAngle;

    normalangle = normalAngle;

    var vx = Math.cos(startangle);

    var vy = Math.sin(startangle);

    var nx = Math.cos(normalangle);

    var ny = Math.sin(normalangle);

    var v_dot_n = vx * nx + vy * ny;

    var rx = vx - 2 * v_dot_n * nx;

    var ry = vy - 2 * v_dot_n * ny;

    var ra = cr.angleTo(0, 0, rx, ry);

  • Great plugin!

    It is better then my light behavior, since my behavior could not get normal vector well.

    I'm glad you like it.

    Feature request:

    Since there has input vector and normal vector, how about adding another expression to get reflection vector?

    Added. Example has been updated too.

  • Johncw87

    Nice! I had saw the source code but had no idea how to improve it for performance at all.

    Only one suggestion, an unique icon is better to be recognized in event sheet.

  • Wow! Thank you for this - it's awesome!!

  • Thanks for this.. very useful

  • [quote:18sy79w1]Using it in a large project is not recommended at this time

    This plugin is really useful. Will it be updated so that it can safely be used in large projects?

  • UberLou

    I had saw the source code, it did not have redundant code.

    All I could image for performance improving in this plugin are

    1. running in webworker, but it will become asynchronous.

    2. using asm.js. It might be a better way, except not all environments has asm.js supporting, and it is not easy since developer needs to write C/C++ first.

  • rexrainbow Thanks for the reply!

  • I've updated the plugin. Line traces now work with tilemaps, but there is currently an issue where flipped tiles will cause the normal to be on the wrong side.

    The example has also been updated with a second layout, which contains a tilemap.

  • Here is a comer case

    The normal vector and reflect vector might have trouble while the hit point is at (or nearby) the cross point of collision polygon's two edges. In the above image, the normal/reflect vector is correct for one edge, but the finally result is wrong.

    Any hint to correct this case?

  • Here is a comer case

    The normal vector and reflect vector might have trouble while the hit point is at (or nearby) the cross point of collision polygon's two edges. In the above image, the normal/reflect vector is correct for one edge, but the finally result is wrong.

    Any hint to correct this case?

    Something I've noticed in other game engines (like Source) is that the trace hit point is never actually on the plane (or line) it hit, but some small distance before it. My plugin is currently giving you the hit point right on the line. Perhaps they add a little space on purpose to avoid exactly this situation?

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