14-07-18, 11:41 | #1 |
Member
Joined: Oct 2014
Posts: 269
|
Moveable to Moveable Distance Condition
TRNG needs a condition to check the distance between two objects (movables). At the moment you can only check the distance from a movable to Lara. A lot of gameplay elements are simply not possible without such a condition.
I wonder whenever it‘s possible to use trigonometry to figure out the distance. if Lara is aligned with both of the objects you could simply use an addition or subtraction to calculate the distance. You would only have to check if Lara is between the objects or not. If that’s the case, use addition, otherwise subtract the distance. Now the problem is, that Lara won’t be aligned in most of the cases. The solution itself is surprisingly easy. You know the two sides of the triangle, the distances between Lara and the objects. The last information needed to calculate the 3rd side is the angle. Now I wonder, is there any way to figure that out ? |
14-07-18, 13:21 | #2 |
Member
Joined: May 2010
Posts: 1,187
|
The math works for sure. The problem is that the TR4 engine (and thus the classic TRLE) does not use float-type values. In fact it uses int-based structures specially designed by Core in areas where storing a float is absolutely crucial, IIRC.
The good news comes with plugins - you can have as many user-defined values as you want for additional memory, and these variables can be of any type, including floats (but also other structures, objects, etc.) I believe AkyV has added float-type variables (similar to the custom local/global variables we already have in TRNG) to one of his plugins, but I don't remember if it's the one that has already been released (Miscellaneous Mix 1 by AkyV) or if it's the one he's currently working on. But instead of using these custom variables I suppose it would be no problem to also write code for directly for checking distance between any two selected objects. As for constructing this condition into a single condition trigger (like a condition for exporting into a script trigger), I'm afraid that problems would arise from the way the flipeffect / action trigger / condition triggers are structured. There are 5 possible fields for any trigger:
One solution would be to have a series of conditions, each having a different distance that the calculated distance value should be compared to and giving a true or false status depending on that comparison. Another option (more convenient IMO) would be to create a new PARAM_ constant, e.g. PARAM_DISTANCE_OBJECT, which would allow you to specify the NGLE index or possibly slot of one of the objects, the minimum or maximum distance between the two objects (possibly other additional parameters), and then select individual PARAM_DISTANCE_OBJECT= 1, (...) commands inside the trigger panel, along with the second object in the <&> field. This is definitely possible, but I don't think it would be worth making a seperate plugin just for this one feature. Maybe AkyV would be interested in adding this feature to his newest plugin which contains many similar mini-features. Perhaps he has even already done it, as I don't check updates regularly. |
14-07-18, 15:50 | #3 |
Member
Joined: Aug 2013
Posts: 686
|
You don't need either angles or floating point maths to figure out the distance between two objects.
The distance between any two points in 3D space can be calculated using the Pythagorean Theorem. Just take the distances on the X, Y, and Z axis, square each of them, add them, and then take the square root of that using the digit method. This method is accurate enough for the TR-engine, which does everything in fixed-point anyway. No floats or angles required. |
14-07-18, 16:31 | #4 | |
Member
Joined: Oct 2014
Posts: 269
|
Quote:
Sometimes it just seems too close to reality and makes me want to use the rules of our real world... Ok so I guess I can dynamically stock the X,Y,Z coordinates of the movables/statics using a GlobalTrigger ? Then I’d have to subtract each of the values to obtain the difference in X,Y,Z. Finally square them and take the root. I know that TRNG’s scripting supports additions, subtractions, multiplication and division but what about power and root ? I believe multiplying the variable with itself should work for the first part, but using the digit method to determine the root seems a bit painful. Isn’t there a premade algorithm by any chance ? Otherwise I’d have to apply the formula on Wikipedia and add up all the digits one by one...It’s way too complicated for what it is, can’t someone simply write a plugin for it ? Please ? Last edited by Nicklander; 14-07-18 at 16:40. |
|
15-07-18, 21:19 | #5 |
Member
Joined: Aug 2013
Posts: 686
|
Almost, you first take each distance and square them individually.
it's (((X)*(X))+((Y)*(Y))+((Z)*(Z))). ( meaning difference). I don't know all that much about TRNG but pretty much every programming language has a square root function (although most of them use a floating-point type). I myself just use the digit method when programming in C, but I suppose such a plug-in shouldn't be too complicated. |
16-07-18, 21:18 | #6 | |
Member
Joined: Oct 2014
Posts: 269
|
Quote:
Last edited by Nicklander; 16-07-18 at 21:20. |
|
Thread Tools | |
|
|