mirror of
https://git.coom.tech/drummyfish/raycastlib.git
synced 2024-11-21 20:29:59 +01:00
Fix collision bug
This commit is contained in:
parent
7d2ccf6753
commit
2cb5142195
1 changed files with 12 additions and 5 deletions
15
raycastlib.h
15
raycastlib.h
|
@ -1514,8 +1514,8 @@ void RCL_moveCameraWithCollision(RCL_Camera *camera, RCL_Vector2D planeOffset,
|
||||||
RCL_Vector2D corner; // BBox corner in the movement direction
|
RCL_Vector2D corner; // BBox corner in the movement direction
|
||||||
RCL_Vector2D cornerNew;
|
RCL_Vector2D cornerNew;
|
||||||
|
|
||||||
int16_t xDir = planeOffset.x > 0 ? 1 : (planeOffset.x < 0 ? -1 : 0);
|
int16_t xDir = planeOffset.x > 0 ? 1 : -1;
|
||||||
int16_t yDir = planeOffset.y > 0 ? 1 : (planeOffset.y < 0 ? -1 : 0);
|
int16_t yDir = planeOffset.y > 0 ? 1 : -1;
|
||||||
|
|
||||||
corner.x = camera->position.x + xDir * RCL_CAMERA_COLL_RADIUS;
|
corner.x = camera->position.x + xDir * RCL_CAMERA_COLL_RADIUS;
|
||||||
corner.y = camera->position.y + yDir * RCL_CAMERA_COLL_RADIUS;
|
corner.y = camera->position.y + yDir * RCL_CAMERA_COLL_RADIUS;
|
||||||
|
@ -1529,9 +1529,16 @@ void RCL_moveCameraWithCollision(RCL_Camera *camera, RCL_Vector2D planeOffset,
|
||||||
xSquareNew = RCL_divRoundDown(cornerNew.x,RCL_UNITS_PER_SQUARE);
|
xSquareNew = RCL_divRoundDown(cornerNew.x,RCL_UNITS_PER_SQUARE);
|
||||||
ySquareNew = RCL_divRoundDown(cornerNew.y,RCL_UNITS_PER_SQUARE);
|
ySquareNew = RCL_divRoundDown(cornerNew.y,RCL_UNITS_PER_SQUARE);
|
||||||
|
|
||||||
RCL_Unit bottomLimit = camera->height - RCL_CAMERA_COLL_HEIGHT_BELOW +
|
RCL_Unit bottomLimit = -1 * RCL_INFINITY;
|
||||||
|
RCL_Unit topLimit = RCL_INFINITY;
|
||||||
|
|
||||||
|
if (computeHeight)
|
||||||
|
{
|
||||||
|
bottomLimit = camera->height - RCL_CAMERA_COLL_HEIGHT_BELOW +
|
||||||
RCL_CAMERA_COLL_STEP_HEIGHT;
|
RCL_CAMERA_COLL_STEP_HEIGHT;
|
||||||
RCL_Unit topLimit = camera->height + RCL_CAMERA_COLL_HEIGHT_ABOVE;
|
|
||||||
|
topLimit = camera->height + RCL_CAMERA_COLL_HEIGHT_ABOVE;
|
||||||
|
}
|
||||||
|
|
||||||
// checks a single square for collision against the camera
|
// checks a single square for collision against the camera
|
||||||
#define collCheck(dir,s1,s2)\
|
#define collCheck(dir,s1,s2)\
|
||||||
|
|
Loading…
Reference in a new issue