Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Entity's Location / Distance to Entity
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#4
RE: Entity's Location / Distance to Entity

Okay, I have written up a distance checking example map:
Download

The sample map will report the distance between the barrel and the box when you use the lantern, and also has a distance callback if the barrel and box are ever within 2 units-of-distance of each other.


How to use it
Spoiler below!

Firstly, I have included python
(3.2) script which generates entities based on a file called "unitSphere.txt". This is in ->entities->SphereGen.

If you want to alter the precision / max range, just delete all the existing entities in that folder, alter the python script accordingly and run again. Note that the precision must be a negative power of two (e.g. 0.125, which is what is currently used).

The map script file also contains some constants (which refer directly to the parameters at the start of the python file) which you would need to alter.


The script file contains a couple of helper functions:
string GetRangeFileName(float range)
float GetRangeValCeil(float range)
You shouldn't need to use these, but their purpose is commented in the script file if you're interested.

I create a variant of "AddEntityCollideCallback", which allows a range to specified:
AddEntityWithinRangeCollideCallback(string &in asBase, string &in asEntity,  string &in asCallback, int alStates, float maxRange)
The callback works is the same as the one from AddEntityCollideCallback. Note that if you want the routine to work with the player, specify "Player" in the asEntity field (* is also supported here, but not in asBase). asBase MUST be an entity which supportes AddAttachedPropToProp. Also note that the asParent feild in the collide callback will be the entity matched by asEntity, and asChild will be the name of the range finder entity (Not asBase).

There is also a RemoveEntityCollideCallback variant, which takes a range parameter.
RemoveEntityWithinRangeCollideCallback(string &in asBase, string &in asEntity, float maxRange)
You may specify multiple range callbacks per entity pairs (E.g. a callback for distance =4, 5 and 6), but not multiple callbacks for the same combination of parent,child and distance.


Finally, there are two find-distance between entity functions. These are FAR slower than the range callback stuff, so use that if you just want to test if x within a certain distance of y. But if you MUST know the distance:
getEntityDistance(string &in asBase, string &in asEntity)
getEntityDistanceLinear(string &in asBase, string &in asEntity)

These both do the same thing. GetEntityDistanceLinear is slower except when the objects are extremely close.
asBase must again be a prop which allows attachments, whereas asEntity can be anything, including "Player", and maybe astrix too.

09-04-2012, 02:22 PM
Find


Messages In This Thread
RE: Entity's Location / Distance to Entity - by Apjjm - 09-04-2012, 02:22 PM



Users browsing this thread: 1 Guest(s)