Raised This Month: $51 Target: $400
 12% 

[Solved]Distance Difference, Two Entities


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sagenth
Member
Join Date: Aug 2010
Old 02-07-2011 , 14:51   [Solved]Distance Difference, Two Entities
Reply With Quote #1

PHP Code:
stock Float:entity_distance_stock(ent1ent2)
{
    new 
Float:orig1[3]
    new 
Float:orig2[3]
    new 
orig
 
    orig 
FindSendPropOffs("CBasePlayer""m_vecOrigin")//sm_dump_netprops
        
GetEntDataVector(ent1origorig1)
        
GetEntDataVector(ent2origorig2)
 
        return 
GetVectorDistance(orig1orig2)

Is this the best or only way to determine the distance between two entities?
Secondly I cannot seem to determine if this accounts for depth.

Ideally I would like to find the differences myself, for each axis.
PHP Code:
xDifference SquareRoot((ent1.ent2.x) * (ent1.ent2.x)) 
Then go and do the same for each axis.

Thirdly, does anybody know a super fast algorithm for square roots that might be faster than the built in SquareRoot(float)?

Useful pages I have found thanks to this thread:

http://wiki.alliedmods.net/Finding_Virtual_Offsets
http://www.bailopan.net/table_dump.txt
http://wiki.alliedmods.net/Vectors_Explained_(Scripting)

Been finding lots of stuff on the wiki that I didn't know was there.

Last edited by Sagenth; 02-08-2011 at 10:03.
Sagenth is offline
zeroibis
Veteran Member
Join Date: Jun 2007
Old 02-07-2011 , 15:12   Re: Distance Difference, Two Entities
Reply With Quote #2

This accounts for x y and z. You can see this in effect via wards on a war3 server. You will find that it takes into account x y and z.

In addition if your just trying to determin a range or something you can use this instead:

/**
* Set the max health of an entity.
*
* @param entity Entity index
* @param value Max health to set (anything above 511 will overload)
* @noreturn
*/

stock bool:Entity_InRange(entity, target, Float:distance);

http://www.sourcemodplugins.org/smlibfunctions.php
__________________
zeroibis is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 02-07-2011 , 15:14   Re: Distance Difference, Two Entities
Reply With Quote #3

If I understand your request correctly, it's the same I had, and the answer I got was SubtractVector. It'll give you the difference between two vectors.
__________________
thetwistedpanda is offline
zeroibis
Veteran Member
Join Date: Jun 2007
Old 02-07-2011 , 15:18   Re: Distance Difference, Two Entities
Reply With Quote #4

Quote:
Originally Posted by thetwistedpanda View Post
If I understand your request correctly, it's the same I had, and the answer I got was SubtractVector. It'll give you the difference between two vectors.
Wow I will be making that update in the future! Much better than:
Code:
localvector[0] = WardLocation[wardindex][0] - targetlocation[0];
localvector[1] = WardLocation[wardindex][1] - targetlocation[1];
localvector[2] = WardLocation[wardindex][2] - targetlocation[2];
__________________
zeroibis is offline
thetwistedpanda
Good Little Panda
Join Date: Sep 2008
Old 02-07-2011 , 15:20   Re: Distance Difference, Two Entities
Reply With Quote #5

Yeah I didn't know about it either, although I got a lot of shit for asking about a better solution than what I was using.
__________________
thetwistedpanda is offline
Sagenth
Member
Join Date: Aug 2010
Old 02-07-2011 , 15:58   Re: Distance Difference, Two Entities
Reply With Quote #6

The application is for the distance one entity is from another in order to find out whether they are in fact in range of one another.

So I guess, as far as anybody knows, there isn't any way to get straight access to the vector data for each axis coord.

That SubtractVector( looks like it would be just as good or better. However I would need to redundantly square and root it to ensure it is positive, or probably faster to just if <0 then *-1
Sagenth is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 02-07-2011 , 16:02   Re: Distance Difference, Two Entities
Reply With Quote #7

vector[0] == x;

Man...
__________________
FaTony is offline
Sagenth
Member
Join Date: Aug 2010
Old 02-07-2011 , 16:08   Re: Distance Difference, Two Entities
Reply With Quote #8

lol well that solves that issue. I am used to accessing vectors as objects, never occurred to me that it might be logically accessed. Like in Linear Algebra, lol goes to show only Microsoft sets things up ass backwards.

XNA:
PHP Code:
public Vector3 QuaternionToEuler(Quaternion q)
{
    
Vector3 v Vector3.Zero;
 
    
v.= (float)Math.Atan2 
    
(
        
q.q.q.q.Z,
           
Math.Pow(q.Y2) - Math.Pow(q.Z2)
    );
 
    
v.= (float)Math.Asin
    
(
        
q.q.q.q.W
    
);
 
    
v.= (float)Math.Atan2
    

Sagenth is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 02-07-2011 , 16:29   Re: Distance Difference, Two Entities
Reply With Quote #9

In case of OO languages and C/C++ especially, it's much better to use structs or classes instead of arrays.
__________________
FaTony is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 02-07-2011 , 16:31   Re: Distance Difference, Two Entities
Reply With Quote #10

GetVectorDistance
__________________
Silvers is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 19:17.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode