[SCRIPT] Entity's Location / Distance to Entity - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html) +---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html) +---- Thread: [SCRIPT] Entity's Location / Distance to Entity (/thread-18149.html) Pages:
1
2
|
Entity's Location / Distance to Entity - craven7 - 09-04-2012 Hi is there any way to get an entity's location or the distance to an other entity or the player? If not, does that mean that the only way to let an entity react with other entities nearby is to place a scriptarea for every one? Also when using the PlayerLookAtCallback a maxDistance would be nice... For example when looking at a picture a message like "What a beautiful picture" should appear, but not when the player is like 20 m away and can hardly see the picture at all. Any solution? Thanks RE: Entity's Location / Distance to Entity - Apjjm - 09-04-2012 If distance is all you are interested in there are some pretty simple hacks that can be used. How precise do you want the distance calculation to be, and how frequently will it be called - if you want too much precision or too much frequency then you will struggle. Also, do you want object origin->object origin distance, or object origin->nearest point on another object distance? RE: Entity's Location / Distance to Entity - craven7 - 09-04-2012 It doesn't have to be that precise... for example player is walking down a corridor and everytime he comes near a door, the door closes. Let's say, check for a nearby door every 0.5 seconds... shouldn't be too costly? RE: Entity's Location / Distance to Entity - Apjjm - 09-04-2012 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!
RE: Entity's Location / Distance to Entity - craven7 - 09-04-2012 First, thanks for you effort. So basically you create a sphere which origin is the entity which I check for its closeness? If we take my example with the doors which shall open when the player approaches, every door "gets" a sphere around itself and if the player collides with it, we know that he's in range. Imho pretty strange that you have to do a workaround with loading the needed sphere entity instead of supporting a function for distance but ok. Strangely when i first started your testmap, ED was always -1 || -1. I reloaded and now it's working. Thank you very much, I will use this method in my custom story. Should I ever come to release it, how do you want to be mentioned in credits? RE: Entity's Location / Distance to Entity - Apjjm - 09-04-2012 Yeah, amnesia scripting doesn't expose positions, as I'm assuming frictional didn't think such behaviour would be needed (also, it probably simplified saving the state of the game, as only stuff using SetLocalVar/SetGlobalVar is saved - rather than saving the state of classes etc in the script). You are correct that my approach is using attached spheres to the origin of props, the callback code just attaches one sphere and creates a collision callback on that sphere. The distance code uses binary (or linear) search over the range of sphere sizes to find the first distance at which the range spheres and the target prop intersect. With regards to the reload - amnesia can do that if you add the entities to the folder whilst it is running. It probably caches a mapping from file names -> file paths so that no file paths need to be specified in scripting, but that cache wasn't updated (i'm guessing it's probably constructed when the resources file is loaded). Don't worry about putting me in the credits, but if you want to include me it's entirely up to you how you mention me . Edit 2: I think it is just that the "In Range" message is a little deceptive. The range message is displaying the name of the child entity, rather than the parent entity. Try the following: Code: void cbTestRange(string &in asParent, string &in asChild, int alState) RE: Entity's Location / Distance to Entity - craven7 - 09-04-2012 Hm i can't get this to work for enemies? Any hint? Code: for(int i = 1; i <= 7; i++) With the wood_box01 it's working. If i replace it with this: Code: for(int i = 1; i <= 7; i++) Code: string attachName = "RANGECB_ BASE: "+asBase+ " ENTITY: " + asEntity+ " RANGE: " +range; Is there a more beautiful ^^ way to get the name of the door than searching for a keyword in the attachName? RE: Entity's Location / Distance to Entity - Your Computer - 09-04-2012 Grunts don't have bodies, and so you can't attach entities to it. RE: Entity's Location / Distance to Entity - craven7 - 09-04-2012 Yes, that's why I replaced the grunt(base) with the doors(entity). But now I have to get the entities name's by using string operations which isn't so nice after all. I'd appreciate to have a more "direct" reference, despite knowing that it's only a string and not an object. RE: Entity's Location / Distance to Entity - Apjjm - 09-04-2012 Replace the Entity Within Range callback section with the following: Code: /////////////////////////////// You then have access to two new functions: Code: string GetBaseFromRangeCallback(string &in asChild) Edit: Alternative solution using string parsing: Spoiler below!
|