Tomb Raider Forums  

Go Back   Tomb Raider Forums > Tomb Raider Level Editor and Modding > Tomb Raider Level Editor > Tomb Raider Next Generation

Reply
 
Thread Tools
Old 14-07-18, 11:41   #1
Nicklander
Member
 
Nicklander's Avatar
 
Joined: Oct 2014
Posts: 269
Post 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 ?
Nicklander is offline   Reply With Quote
Old 14-07-18, 13:21   #2
Krystian
Member
 
Joined: May 2010
Posts: 1,187
Default

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:
  • Trigger (what to trigger)
  • Object to trigger <#>
  • Trigger type (activation mode)
  • Timer field <&>
  • Extra field (E)
The Trigger and Trigger type fields are always occupied, and in the case of actions and conditions, the timer field is designated for describing which kind of action or condition you want to use (E.g. Move to north <#> object by (E) units, Lara has <#> item present in inventory). This leaves you with only two fields, the Object to trigger and Extra fields. Say you would use these two fields for selecting the two objects you would like to check the distance from. But this leaves you with no field for having the calculated distance compared to something (a preset value or a value from PARAM_BIG_NUMBER) or even to designate which of the custom variables the calculated distance should be put into.

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.
Krystian is offline   Reply With Quote
Old 14-07-18, 15:50   #3
b122251
Member
 
b122251's Avatar
 
Joined: Aug 2013
Posts: 686
Default

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.
b122251 is offline   Reply With Quote
Old 14-07-18, 16:31   #4
Nicklander
Member
 
Nicklander's Avatar
 
Joined: Oct 2014
Posts: 269
Default

Quote:
Originally Posted by b122251 View Post
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.
Oh yes sure ! How could I forget that TR is actually a game !
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.
Nicklander is offline   Reply With Quote
Old 15-07-18, 21:19   #5
b122251
Member
 
b122251's Avatar
 
Joined: Aug 2013
Posts: 686
Default

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.
b122251 is offline   Reply With Quote
Old 16-07-18, 21:18   #6
Nicklander
Member
 
Nicklander's Avatar
 
Joined: Oct 2014
Posts: 269
Default

Quote:
Originally Posted by b122251 View Post
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.
It’s been a while I’ve done geometry in school. Thanks for your help ! AkyV plans to integrate it in his plugin.

Last edited by Nicklander; 16-07-18 at 21:20.
Nicklander is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 14:30.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Tomb Raider Forums is not owned or operated by CDE Entertainment Ltd.
Lara Croft and Tomb Raider are trademarks of CDE Entertainment Ltd.