Author Topic: Activate different parts of a brick?  (Read 2997 times)

Same principle. You get the hit point of your eye vector and check if it's transform is within a certain area

As far as determining which surface you are looking at, you can use raycasts. I did something like this in Trench Digging Plus. Here's a succinct version of what I did in my code

Code: [Select]
%eyePoint = %client.player.getEyePoint();
%eyeVector = %client.player.getEyeVector();
%pos = vectorAdd(%eyePoint, 100); // You will probably want to tweak the range here; 100 is probably too big for your purposes
%ray = containerRayCast(%eyePoint, %pos, $TypeMasks::FxBrickObjectType);
%brick = firstWord(%ray);
%normal = normalFromRayCast(%ray);

That %normal will tell you what surface the player is looking at. A normal of "0 0 1" indicates the top surface, "0 0 -1" the bottom, and "0 1 0", "1 0 0", "0 -1 0", "-1 0 0" the north, east, south and west surfaces, respectively (I am not sure if these are conventionally considered north, south, east, and west, but it is how I refer to them). One thing to note is that the normal vectors are not always perfect. That is, you might get a vector more like "6.172444e-123 0 1" instead of "0 0 1". If you're just dealing with basic normal surfaces (no inclined or oblique surfaces), then you can just round each coordinate value.



Are you trying to create event triggers, like onActivateTop or onActivateNorth, etc.?
« Last Edit: February 28, 2018, 06:51:23 PM by Platypi »

Are you trying to create event triggers, like onActivateTop or onActivateNorth, etc.?

Thanks for the help:) And about the events, possibly. At first I wanted it to do it automatically but now I think it might be better the other way

You cannot assume normals will be some variant or close variant of 0 0 1/0 1 0/1 0 0 as it does return the normal of the surface hit. For example, if your raycast hits a ramp brick or static shape, it will return the normal of the face hit

You cannot assume normals will be some variant or close variant of 0 0 1/0 1 0/1 0 0 as it does return the normal of the surface hit. For example, if your raycast hits a ramp brick or static shape, it will return the normal of the face hit

If you're just dealing with basic normal surfaces (no inclined or oblique surfaces), then you can just round each coordinate value.

If you're only creating triggers for normal surfaces, rounding within 0.001 (or something similar) should provide enough accuracy. Normals that fall outside that bound can be considered inclined or oblique, and simply be ignored. I'm not sure how you could create event triggers for inclined or oblique surfaces without creating an ungodly number of them.