[Plugin] jcw_trace (raycast)

Post your work in progress addons and get feedback

Post » Fri May 06, 2016 4:11 am

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.
Last edited by Johncw87 on Wed Mar 22, 2017 1:46 am, edited 5 times in total.
B
54
S
19
G
13
Posts: 97
Reputation: 10,146

Post » Fri May 06, 2016 5:17 am

Great plugin!

It is better then my light behavior, since my behavior could not get normal vector well.
B
108
S
26
G
260
Posts: 4,435
Reputation: 146,193

Post » Fri May 06, 2016 6:01 am

Feature request:

Since there has input vector and normal vector, how about adding another expression to get reflection vector?
B
108
S
26
G
260
Posts: 4,435
Reputation: 146,193

Post » Fri May 06, 2016 6:36 am

@rexrainbow
What formula does the bullet behavior use?
Image ImageImage
B
168
S
50
G
164
Posts: 8,231
Reputation: 105,581

Post » Fri May 06, 2016 7:00 am

@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);
B
108
S
26
G
260
Posts: 4,435
Reputation: 146,193

Post » Fri May 06, 2016 8:51 am

rexrainbow wrote:Great plugin!

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


I'm glad you like it.

rexrainbow wrote: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.
B
54
S
19
G
13
Posts: 97
Reputation: 10,146

Post » Fri May 06, 2016 9:01 am

@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.
B
108
S
26
G
260
Posts: 4,435
Reputation: 146,193

Post » Fri May 06, 2016 10:25 am

Wow! Thank you for this - it's awesome!!
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,193

Post » Fri May 06, 2016 1:09 pm

Thanks for this.. very useful :)
B
47
S
16
G
9
Posts: 1,097
Reputation: 11,180

Post » Mon May 09, 2016 12:59 am

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?
B
79
S
51
G
40
Posts: 370
Reputation: 25,205

Next

Return to Work in Progress Addons

Who is online

Users browsing this forum: No registered users and 0 guests