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
[SOLVED] How to get distance to enemy?
Mafiyia Offline
Junior Member

Posts: 7
Threads: 4
Joined: Jan 2017
Reputation: 0
#1
[SOLVED] How to get distance to enemy?

I'm creating an add-on mod where I would like to get the distance to an enemy. After researching the documentation I have been trying to use the Player_GetDistanceToEntity(const tString &in asEntity) function where asEntity is the entity's name. But I'm having a hard time figuring out what I should use as the entity's name.

For example in Chapter 1 in Upsilon Awake there is an enemy according to the Wiki called 'Construct'. I've used Construct, construct, construct_theta, infected_robot, etc. as input into the function but I always get a entity does not exist in my debug messages.

I even tried loading up the map in the Level Editor to see if I could find it, but the map is so cluttered that it made this task pretty much impossible.

So does anyone know where I could find what the asEntity names should be or any better methods to find the distance to enemy?
(This post was last modified: 01-30-2017, 10:31 PM by Mafiyia.)
01-27-2017, 07:53 PM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#2
RE: How to get distance to enemy?

asEntity refers to the name of the Entity as it is defined in the Level Editor.

A slightly better way to do it, though I don't know the exact syntax, would be to get the name of the entity that the Player is currently looking at, then pass that value into Player_GetDistanceToEntity(), otherwise you need to add conditionals for every specific entity.

PHP Code: (Select All)
tString entityName Player_GetFocusEntityName();      //Maybe?
float entityDist Player_GetDistanceToEntity(entityName);
cLux_AddDebugMessage(entityName " is " entityDist "f units away."false); 

Discord: Romulator#0001
[Image: 3f6f01a904.png]
(This post was last modified: 01-27-2017, 09:48 PM by Romulator.)
01-27-2017, 09:47 PM
Find
Abion47 Offline
Senior Member

Posts: 369
Threads: 22
Joined: Oct 2015
Reputation: 46
#3
RE: How to get distance to enemy?

There are three ways to do the distance problem, and they all require the name of the monster's entity. Like Romulator said, the "name" is just the value of the monster entity that is inside the "Name" box in the Level Editor. If, for example, that box looks like this:

[Image: UMfw1kl.png]

Then the name you would use in your script would be "super_scary_monster".

Now the first approach is what you are currently doing - use Player_GetDistanceToEntity:

float distance = Player_GetDistanceToEntity("super_scary_monster");

The second is getting the positions of both the player and the entity and doing some vector math:

cVector3f pPos = Player_GetPosition();
cVector3f ePos = Map_GetEntity("super_scary_monster").GetPosition();

float distance = (ePos - pPos).Length();

And the third is doing all the math yourself:

cVector3f pPos = Player_GetPosition();
cVector3f ePos = Map_GetEntity("super_scary_monster").GetPosition();

float distance = cMath_Sqrt((pPos.x - ePos.x) * (pPos.x - ePos.x)
                          + (pPos.y - ePos.y) * (pPos.y - ePos.y)
                          + (pPos.z - ePos.z) * (pPos.z - ePos.z));

The second one is basically what the first one does anyway, and the third one, though somewhat cool (depending on your point of view), is quite verbose, so yeah, you should go ahead and stick to the first one.

(This post was last modified: 01-28-2017, 12:04 AM by Abion47.)
01-27-2017, 11:59 PM
Find
Mafiyia Offline
Junior Member

Posts: 7
Threads: 4
Joined: Jan 2017
Reputation: 0
#4
RE: [SOLVED] How to get distance to enemy?

Thanks for the help!
01-30-2017, 10:32 PM
Find




Users browsing this thread: 1 Guest(s)