примерное определение:
float Distance = Vector3::distance((Vector3 позиции localPlayer), (Vector3 позиции Entity));
примерная реализация Vector3:
struct Vector3
{
float x, y, z;
Vector3(float x = 0, float y = 0, float z = 0) : x(x), y(y), z(z) {}
friend std::ostream& operator<<(std::ostream& os, const Vector3& v) // для вывода
{
os << "(" << v.x << ", " << v.y << ", " << v.z << ")";
return os;
}
Vector3 operator+(const Vector3& other) const
{
return Vector3(x + other.x, y + other.y, z + other.z);
}
Vector3 operator-(const Vector3& other) const
{
return Vector3(x - other.x, y - other.y, z - other.z);
}
Vector3 operator*(float scalar) const
{
return Vector3(x * scalar, y * scalar, z * scalar);
}
Vector3 operator/(float scalar) const
{
return Vector3(x / scalar, y / scalar, z / scalar);
}
static float distance(const Vector3& v1, const Vector3& v2)
{
float dx = v1.x - v2.x;
float dy = v1.y - v2.y;
float dz = v1.z - v2.z;
return std::sqrt(dx * dx + dy * dy + dz * dz);
}
};