Jump to content

LE 3 simple distance check functions:


YouGroove
 Share

Recommended Posts

I would want to check distance between player and goblin with a simple Cylinder check.

 

Does some people knwo how to do that in Lua :

If a point is inside a 2D circle (the point is the barbarian origin, the owner of the circle center is the goblin)

 

 

I'll do simple bouding box check also : a point inside a box volume.

 

I find these way of doing lot more simple than the AABB stuff i seen in GoblinAI , even with good explanation i dunderstand , but why calling that when you can just makeit simple ?

Perhaps it is same in terms of speed ?

 

Another point of optimisation is to check distance only each 5 or 15 frames, it's not a simulation game.

Stop toying and make games

Link to comment
Share on other sites

Distance is calculated by simply getting the squareroot of the sum of the squared differences of 2 entity's positions:

distance = sqrt( ((p2.x-p1.x)*(p2.x-p1.x)) + ((p2.y-p1.y)*(p2.y-p1.y)) + ((p2.z-p1.z)*(p2.z-p1.z)) )

http://en.wikipedia.org/wiki/Euclidean_distance

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

distance = sqrt( ((p2.x-p1.x)*(p2.x-p1.x)) + ((p2.y-p1.y)*(p2.y-p1.y)) + ((p2.z-p1.z)*(p2.z-p1.z)) )

 

How would I relate this code to Entity_1 Entity_2?

amd quad core 4 ghz / geforce 660 ti 2gb / win 10

Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++

Link to comment
Share on other sites

C++

Vec3 position = entity->GetPosition(true);
float dist = position.DistanceToPoint(otherentity->GetPosition(true));

 

Lua:

local position = entity:GetPosition(true)

local dist = position:DistanceToPoint( otherentity:GetPosition(true) )

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...