collision.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "collision.h"
  17. #include <cmath>
  18. #include "mapblock.h"
  19. #include "map.h"
  20. #include "nodedef.h"
  21. #include "gamedef.h"
  22. #ifndef SERVER
  23. #include "client/clientenvironment.h"
  24. #endif
  25. #include "serverenvironment.h"
  26. #include "serverobject.h"
  27. #include "util/timetaker.h"
  28. #include "profiler.h"
  29. // float error is 10 - 9.96875 = 0.03125
  30. //#define COLL_ZERO 0.032 // broken unit tests
  31. #define COLL_ZERO 0
  32. struct NearbyCollisionInfo {
  33. NearbyCollisionInfo(bool is_ul, bool is_obj, int bouncy,
  34. const v3s16 &pos, const aabb3f &box) :
  35. is_unloaded(is_ul),
  36. is_object(is_obj),
  37. bouncy(bouncy),
  38. position(pos),
  39. box(box)
  40. {}
  41. bool is_unloaded;
  42. bool is_step_up = false;
  43. bool is_object;
  44. int bouncy;
  45. v3s16 position;
  46. aabb3f box;
  47. };
  48. // Helper function:
  49. // Checks for collision of a moving aabbox with a static aabbox
  50. // Returns -1 if no collision, 0 if X collision, 1 if Y collision, 2 if Z collision
  51. // The time after which the collision occurs is stored in dtime.
  52. CollisionAxis axisAlignedCollision(
  53. const aabb3f &staticbox, const aabb3f &movingbox,
  54. const v3f &speed, f32 d, f32 *dtime)
  55. {
  56. //TimeTaker tt("axisAlignedCollision");
  57. f32 xsize = (staticbox.MaxEdge.X - staticbox.MinEdge.X) - COLL_ZERO; // reduce box size for solve collision stuck (flying sand)
  58. f32 ysize = (staticbox.MaxEdge.Y - staticbox.MinEdge.Y); // - COLL_ZERO; // Y - no sense for falling, but maybe try later
  59. f32 zsize = (staticbox.MaxEdge.Z - staticbox.MinEdge.Z) - COLL_ZERO;
  60. aabb3f relbox(
  61. movingbox.MinEdge.X - staticbox.MinEdge.X,
  62. movingbox.MinEdge.Y - staticbox.MinEdge.Y,
  63. movingbox.MinEdge.Z - staticbox.MinEdge.Z,
  64. movingbox.MaxEdge.X - staticbox.MinEdge.X,
  65. movingbox.MaxEdge.Y - staticbox.MinEdge.Y,
  66. movingbox.MaxEdge.Z - staticbox.MinEdge.Z
  67. );
  68. if(speed.X > 0) // Check for collision with X- plane
  69. {
  70. if (relbox.MaxEdge.X <= d) {
  71. *dtime = -relbox.MaxEdge.X / speed.X;
  72. if ((relbox.MinEdge.Y + speed.Y * (*dtime) < ysize) &&
  73. (relbox.MaxEdge.Y + speed.Y * (*dtime) > COLL_ZERO) &&
  74. (relbox.MinEdge.Z + speed.Z * (*dtime) < zsize) &&
  75. (relbox.MaxEdge.Z + speed.Z * (*dtime) > COLL_ZERO))
  76. return COLLISION_AXIS_X;
  77. }
  78. else if(relbox.MinEdge.X > xsize)
  79. {
  80. return COLLISION_AXIS_NONE;
  81. }
  82. }
  83. else if(speed.X < 0) // Check for collision with X+ plane
  84. {
  85. if (relbox.MinEdge.X >= xsize - d) {
  86. *dtime = (xsize - relbox.MinEdge.X) / speed.X;
  87. if ((relbox.MinEdge.Y + speed.Y * (*dtime) < ysize) &&
  88. (relbox.MaxEdge.Y + speed.Y * (*dtime) > COLL_ZERO) &&
  89. (relbox.MinEdge.Z + speed.Z * (*dtime) < zsize) &&
  90. (relbox.MaxEdge.Z + speed.Z * (*dtime) > COLL_ZERO))
  91. return COLLISION_AXIS_X;
  92. }
  93. else if(relbox.MaxEdge.X < 0)
  94. {
  95. return COLLISION_AXIS_NONE;
  96. }
  97. }
  98. // NO else if here
  99. if(speed.Y > 0) // Check for collision with Y- plane
  100. {
  101. if (relbox.MaxEdge.Y <= d) {
  102. *dtime = -relbox.MaxEdge.Y / speed.Y;
  103. if ((relbox.MinEdge.X + speed.X * (*dtime) < xsize) &&
  104. (relbox.MaxEdge.X + speed.X * (*dtime) > COLL_ZERO) &&
  105. (relbox.MinEdge.Z + speed.Z * (*dtime) < zsize) &&
  106. (relbox.MaxEdge.Z + speed.Z * (*dtime) > COLL_ZERO))
  107. return COLLISION_AXIS_Y;
  108. }
  109. else if(relbox.MinEdge.Y > ysize)
  110. {
  111. return COLLISION_AXIS_NONE;
  112. }
  113. }
  114. else if(speed.Y < 0) // Check for collision with Y+ plane
  115. {
  116. if (relbox.MinEdge.Y >= ysize - d) {
  117. *dtime = (ysize - relbox.MinEdge.Y) / speed.Y;
  118. if ((relbox.MinEdge.X + speed.X * (*dtime) < xsize) &&
  119. (relbox.MaxEdge.X + speed.X * (*dtime) > COLL_ZERO) &&
  120. (relbox.MinEdge.Z + speed.Z * (*dtime) < zsize) &&
  121. (relbox.MaxEdge.Z + speed.Z * (*dtime) > COLL_ZERO))
  122. return COLLISION_AXIS_Y;
  123. }
  124. else if(relbox.MaxEdge.Y < 0)
  125. {
  126. return COLLISION_AXIS_NONE;
  127. }
  128. }
  129. // NO else if here
  130. if(speed.Z > 0) // Check for collision with Z- plane
  131. {
  132. if (relbox.MaxEdge.Z <= d) {
  133. *dtime = -relbox.MaxEdge.Z / speed.Z;
  134. if ((relbox.MinEdge.X + speed.X * (*dtime) < xsize) &&
  135. (relbox.MaxEdge.X + speed.X * (*dtime) > COLL_ZERO) &&
  136. (relbox.MinEdge.Y + speed.Y * (*dtime) < ysize) &&
  137. (relbox.MaxEdge.Y + speed.Y * (*dtime) > COLL_ZERO))
  138. return COLLISION_AXIS_Z;
  139. }
  140. //else if(relbox.MinEdge.Z > zsize)
  141. //{
  142. // return COLLISION_AXIS_NONE;
  143. //}
  144. }
  145. else if(speed.Z < 0) // Check for collision with Z+ plane
  146. {
  147. if (relbox.MinEdge.Z >= zsize - d) {
  148. *dtime = (zsize - relbox.MinEdge.Z) / speed.Z;
  149. if ((relbox.MinEdge.X + speed.X * (*dtime) < xsize) &&
  150. (relbox.MaxEdge.X + speed.X * (*dtime) > COLL_ZERO) &&
  151. (relbox.MinEdge.Y + speed.Y * (*dtime) < ysize) &&
  152. (relbox.MaxEdge.Y + speed.Y * (*dtime) > COLL_ZERO))
  153. return COLLISION_AXIS_Z;
  154. }
  155. //else if(relbox.MaxEdge.Z < 0)
  156. //{
  157. // return COLLISION_AXIS_NONE;
  158. //}
  159. }
  160. return COLLISION_AXIS_NONE;
  161. }
  162. // Helper function:
  163. // Checks if moving the movingbox up by the given distance would hit a ceiling.
  164. bool wouldCollideWithCeiling(
  165. const std::vector<NearbyCollisionInfo> &cinfo,
  166. const aabb3f &movingbox,
  167. f32 y_increase, f32 d)
  168. {
  169. //TimeTaker tt("wouldCollideWithCeiling");
  170. assert(y_increase >= 0); // pre-condition
  171. for (const auto &it : cinfo) {
  172. const aabb3f &staticbox = it.box;
  173. if ((movingbox.MaxEdge.Y - d <= staticbox.MinEdge.Y) &&
  174. (movingbox.MaxEdge.Y + y_increase > staticbox.MinEdge.Y) &&
  175. (movingbox.MinEdge.X < staticbox.MaxEdge.X) &&
  176. (movingbox.MaxEdge.X > staticbox.MinEdge.X) &&
  177. (movingbox.MinEdge.Z < staticbox.MaxEdge.Z) &&
  178. (movingbox.MaxEdge.Z > staticbox.MinEdge.Z))
  179. return true;
  180. }
  181. return false;
  182. }
  183. static inline void getNeighborConnectingFace(const v3s16 &p,
  184. const NodeDefManager *nodedef, Map *map, MapNode n, int v, int *neighbors)
  185. {
  186. MapNode n2 = map->getNode(p);
  187. if (nodedef->nodeboxConnects(n, n2, v))
  188. *neighbors |= v;
  189. }
  190. collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
  191. f32 pos_max_d, const aabb3f &box_0,
  192. f32 stepheight, f32 dtime,
  193. v3f *pos_f, v3f *speed_f,
  194. v3f accel_f, ActiveObject *self,
  195. bool collideWithObjects)
  196. {
  197. static bool time_notification_done = false;
  198. Map *map = &env->getMap();
  199. ScopeProfiler sp(g_profiler, "collisionMoveSimple()", SPT_AVG);
  200. collisionMoveResult result;
  201. /*
  202. Calculate new velocity
  203. */
  204. if (dtime > 0.5f) {
  205. if (!time_notification_done) {
  206. time_notification_done = true;
  207. infostream << "collisionMoveSimple: maximum step interval exceeded,"
  208. " lost movement details!"<<std::endl;
  209. }
  210. dtime = 0.5f;
  211. } else {
  212. time_notification_done = false;
  213. }
  214. *speed_f += accel_f * dtime;
  215. // If there is no speed, there are no collisions
  216. if (speed_f->getLength() == 0)
  217. return result;
  218. // Limit speed for avoiding hangs
  219. speed_f->Y = rangelim(speed_f->Y, -5000, 5000);
  220. speed_f->X = rangelim(speed_f->X, -5000, 5000);
  221. speed_f->Z = rangelim(speed_f->Z, -5000, 5000);
  222. /*
  223. Collect node boxes in movement range
  224. */
  225. std::vector<NearbyCollisionInfo> cinfo;
  226. {
  227. //TimeTaker tt2("collisionMoveSimple collect boxes");
  228. ScopeProfiler sp2(g_profiler, "collisionMoveSimple(): collect boxes", SPT_AVG);
  229. v3f newpos_f = *pos_f + *speed_f * dtime;
  230. v3f minpos_f(
  231. MYMIN(pos_f->X, newpos_f.X),
  232. MYMIN(pos_f->Y, newpos_f.Y) + 0.01f * BS, // bias rounding, player often at +/-n.5
  233. MYMIN(pos_f->Z, newpos_f.Z)
  234. );
  235. v3f maxpos_f(
  236. MYMAX(pos_f->X, newpos_f.X),
  237. MYMAX(pos_f->Y, newpos_f.Y),
  238. MYMAX(pos_f->Z, newpos_f.Z)
  239. );
  240. v3s16 min = floatToInt(minpos_f + box_0.MinEdge, BS) - v3s16(1, 1, 1);
  241. v3s16 max = floatToInt(maxpos_f + box_0.MaxEdge, BS) + v3s16(1, 1, 1);
  242. bool any_position_valid = false;
  243. v3s16 p;
  244. for (p.X = min.X; p.X <= max.X; p.X++)
  245. for (p.Y = min.Y; p.Y <= max.Y; p.Y++)
  246. for (p.Z = min.Z; p.Z <= max.Z; p.Z++) {
  247. bool is_position_valid;
  248. MapNode n = map->getNode(p, &is_position_valid);
  249. if (is_position_valid && n.getContent() != CONTENT_IGNORE) {
  250. // Object collides into walkable nodes
  251. any_position_valid = true;
  252. const NodeDefManager *nodedef = gamedef->getNodeDefManager();
  253. const ContentFeatures &f = nodedef->get(n);
  254. if (!f.walkable)
  255. continue;
  256. int n_bouncy_value = itemgroup_get(f.groups, "bouncy");
  257. int neighbors = 0;
  258. if (f.drawtype == NDT_NODEBOX &&
  259. f.node_box.type == NODEBOX_CONNECTED) {
  260. v3s16 p2 = p;
  261. p2.Y++;
  262. getNeighborConnectingFace(p2, nodedef, map, n, 1, &neighbors);
  263. p2 = p;
  264. p2.Y--;
  265. getNeighborConnectingFace(p2, nodedef, map, n, 2, &neighbors);
  266. p2 = p;
  267. p2.Z--;
  268. getNeighborConnectingFace(p2, nodedef, map, n, 4, &neighbors);
  269. p2 = p;
  270. p2.X--;
  271. getNeighborConnectingFace(p2, nodedef, map, n, 8, &neighbors);
  272. p2 = p;
  273. p2.Z++;
  274. getNeighborConnectingFace(p2, nodedef, map, n, 16, &neighbors);
  275. p2 = p;
  276. p2.X++;
  277. getNeighborConnectingFace(p2, nodedef, map, n, 32, &neighbors);
  278. }
  279. std::vector<aabb3f> nodeboxes;
  280. n.getCollisionBoxes(gamedef->ndef(), &nodeboxes, neighbors);
  281. // Calculate float position only once
  282. v3f posf = intToFloat(p, BS);
  283. for (auto box : nodeboxes) {
  284. box.MinEdge += posf;
  285. box.MaxEdge += posf;
  286. cinfo.emplace_back(false, false, n_bouncy_value, p, box);
  287. }
  288. } else {
  289. // Collide with unloaded nodes (position invalid) and loaded
  290. // CONTENT_IGNORE nodes (position valid)
  291. aabb3f box = getNodeBox(p, BS);
  292. cinfo.emplace_back(true, false, 0, p, box);
  293. }
  294. }
  295. // Do not move if world has not loaded yet, since custom node boxes
  296. // are not available for collision detection.
  297. // This also intentionally occurs in the case of the object being positioned
  298. // solely on loaded CONTENT_IGNORE nodes, no matter where they come from.
  299. if (!any_position_valid) {
  300. *speed_f = v3f(0, 0, 0);
  301. return result;
  302. }
  303. } // tt2
  304. if(collideWithObjects)
  305. {
  306. /* add object boxes to cinfo */
  307. std::vector<ActiveObject*> objects;
  308. #ifndef SERVER
  309. ClientEnvironment *c_env = dynamic_cast<ClientEnvironment*>(env);
  310. if (c_env != 0) {
  311. // Calculate distance by speed, add own extent and 1.5m of tolerance
  312. f32 distance = speed_f->getLength() * dtime +
  313. box_0.getExtent().getLength() + 1.5f * BS;
  314. std::vector<DistanceSortedActiveObject> clientobjects;
  315. c_env->getActiveObjects(*pos_f, distance, clientobjects);
  316. for (auto &clientobject : clientobjects) {
  317. // Do collide with everything but itself and the parent CAO
  318. if (!self || (self != clientobject.obj &&
  319. self != clientobject.obj->getParent())) {
  320. objects.push_back((ActiveObject*) clientobject.obj);
  321. }
  322. }
  323. }
  324. else
  325. #endif
  326. {
  327. ServerEnvironment *s_env = dynamic_cast<ServerEnvironment*>(env);
  328. if (s_env != NULL) {
  329. // Calculate distance by speed, add own extent and 1.5m of tolerance
  330. f32 distance = speed_f->getLength() * dtime +
  331. box_0.getExtent().getLength() + 1.5f * BS;
  332. std::vector<u16> s_objects;
  333. s_env->getObjectsInsideRadius(s_objects, *pos_f, distance);
  334. for (u16 obj_id : s_objects) {
  335. ServerActiveObject *current = s_env->getActiveObject(obj_id);
  336. if (!self || (self != current &&
  337. self != current->getParent())) {
  338. objects.push_back((ActiveObject*)current);
  339. }
  340. }
  341. }
  342. }
  343. for (std::vector<ActiveObject*>::const_iterator iter = objects.begin();
  344. iter != objects.end(); ++iter) {
  345. ActiveObject *object = *iter;
  346. if (object) {
  347. aabb3f object_collisionbox;
  348. if (object->getCollisionBox(&object_collisionbox) &&
  349. object->collideWithObjects()) {
  350. cinfo.emplace_back(false, true, 0, v3s16(), object_collisionbox);
  351. }
  352. }
  353. }
  354. } //tt3
  355. /*
  356. Collision detection
  357. */
  358. /*
  359. Collision uncertainty radius
  360. Make it a bit larger than the maximum distance of movement
  361. */
  362. f32 d = pos_max_d * 1.1f;
  363. // A fairly large value in here makes moving smoother
  364. //f32 d = 0.15*BS;
  365. // This should always apply, otherwise there are glitches
  366. assert(d > pos_max_d); // invariant
  367. int loopcount = 0;
  368. while(dtime > BS * 1e-10f) {
  369. // Avoid infinite loop
  370. loopcount++;
  371. if (loopcount >= 100) {
  372. warningstream << "collisionMoveSimple: Loop count exceeded, aborting to avoid infiniite loop" << std::endl;
  373. break;
  374. }
  375. aabb3f movingbox = box_0;
  376. movingbox.MinEdge += *pos_f;
  377. movingbox.MaxEdge += *pos_f;
  378. CollisionAxis nearest_collided = COLLISION_AXIS_NONE;
  379. f32 nearest_dtime = dtime;
  380. int nearest_boxindex = -1;
  381. /*
  382. Go through every nodebox, find nearest collision
  383. */
  384. for (u32 boxindex = 0; boxindex < cinfo.size(); boxindex++) {
  385. const NearbyCollisionInfo &box_info = cinfo[boxindex];
  386. // Ignore if already stepped up this nodebox.
  387. if (box_info.is_step_up)
  388. continue;
  389. // Find nearest collision of the two boxes (raytracing-like)
  390. f32 dtime_tmp;
  391. CollisionAxis collided = axisAlignedCollision(box_info.box,
  392. movingbox, *speed_f, d, &dtime_tmp);
  393. if (collided == -1 || dtime_tmp >= nearest_dtime)
  394. continue;
  395. nearest_dtime = dtime_tmp;
  396. nearest_collided = collided;
  397. nearest_boxindex = boxindex;
  398. }
  399. if (nearest_collided == COLLISION_AXIS_NONE) {
  400. // No collision with any collision box.
  401. *pos_f += *speed_f * dtime;
  402. dtime = 0; // Set to 0 to avoid "infinite" loop due to small FP numbers
  403. } else {
  404. // Otherwise, a collision occurred.
  405. NearbyCollisionInfo &nearest_info = cinfo[nearest_boxindex];
  406. const aabb3f& cbox = nearest_info.box;
  407. // Check for stairs.
  408. bool step_up = (nearest_collided != COLLISION_AXIS_Y) && // must not be Y direction
  409. (movingbox.MinEdge.Y < cbox.MaxEdge.Y) &&
  410. (movingbox.MinEdge.Y + stepheight > cbox.MaxEdge.Y) &&
  411. (!wouldCollideWithCeiling(cinfo, movingbox,
  412. cbox.MaxEdge.Y - movingbox.MinEdge.Y,
  413. d));
  414. // Get bounce multiplier
  415. float bounce = -(float)nearest_info.bouncy / 100.0f;
  416. // Move to the point of collision and reduce dtime by nearest_dtime
  417. if (nearest_dtime < 0) {
  418. // Handle negative nearest_dtime (can be caused by the d allowance)
  419. if (!step_up) {
  420. if (nearest_collided == COLLISION_AXIS_X)
  421. pos_f->X += speed_f->X * nearest_dtime;
  422. if (nearest_collided == COLLISION_AXIS_Y)
  423. pos_f->Y += speed_f->Y * nearest_dtime;
  424. if (nearest_collided == COLLISION_AXIS_Z)
  425. pos_f->Z += speed_f->Z * nearest_dtime;
  426. }
  427. } else {
  428. *pos_f += *speed_f * nearest_dtime;
  429. dtime -= nearest_dtime;
  430. }
  431. bool is_collision = true;
  432. if (nearest_info.is_unloaded)
  433. is_collision = false;
  434. CollisionInfo info;
  435. if (nearest_info.is_object)
  436. info.type = COLLISION_OBJECT;
  437. else
  438. info.type = COLLISION_NODE;
  439. info.node_p = nearest_info.position;
  440. info.old_speed = *speed_f;
  441. info.plane = nearest_collided;
  442. // Set the speed component that caused the collision to zero
  443. if (step_up) {
  444. // Special case: Handle stairs
  445. nearest_info.is_step_up = true;
  446. is_collision = false;
  447. } else if (nearest_collided == COLLISION_AXIS_X) {
  448. if (fabs(speed_f->X) > BS * 3)
  449. speed_f->X *= bounce;
  450. else
  451. speed_f->X = 0;
  452. result.collides = true;
  453. } else if (nearest_collided == COLLISION_AXIS_Y) {
  454. if(fabs(speed_f->Y) > BS * 3)
  455. speed_f->Y *= bounce;
  456. else
  457. speed_f->Y = 0;
  458. result.collides = true;
  459. } else if (nearest_collided == COLLISION_AXIS_Z) {
  460. if (fabs(speed_f->Z) > BS * 3)
  461. speed_f->Z *= bounce;
  462. else
  463. speed_f->Z = 0;
  464. result.collides = true;
  465. }
  466. info.new_speed = *speed_f;
  467. if (info.new_speed.getDistanceFrom(info.old_speed) < 0.1f * BS)
  468. is_collision = false;
  469. if (is_collision) {
  470. info.axis = nearest_collided;
  471. result.collisions.push_back(info);
  472. }
  473. }
  474. }
  475. /*
  476. Final touches: Check if standing on ground, step up stairs.
  477. */
  478. aabb3f box = box_0;
  479. box.MinEdge += *pos_f;
  480. box.MaxEdge += *pos_f;
  481. for (const auto &box_info : cinfo) {
  482. const aabb3f &cbox = box_info.box;
  483. /*
  484. See if the object is touching ground.
  485. Object touches ground if object's minimum Y is near node's
  486. maximum Y and object's X-Z-area overlaps with the node's
  487. X-Z-area.
  488. Use 0.15*BS so that it is easier to get on a node.
  489. */
  490. if (cbox.MaxEdge.X - d > box.MinEdge.X && cbox.MinEdge.X + d < box.MaxEdge.X &&
  491. cbox.MaxEdge.Z - d > box.MinEdge.Z &&
  492. cbox.MinEdge.Z + d < box.MaxEdge.Z) {
  493. if (box_info.is_step_up) {
  494. pos_f->Y += cbox.MaxEdge.Y - box.MinEdge.Y;
  495. box = box_0;
  496. box.MinEdge += *pos_f;
  497. box.MaxEdge += *pos_f;
  498. }
  499. if (std::fabs(cbox.MaxEdge.Y - box.MinEdge.Y) < 0.15f * BS) {
  500. result.touching_ground = true;
  501. if (box_info.is_object)
  502. result.standing_on_object = true;
  503. }
  504. }
  505. }
  506. return result;
  507. }