Skip to content

Commit

Permalink
adjust arms hitbox to match voxlap
Browse files Browse the repository at this point in the history
  • Loading branch information
siecvi committed Jul 17, 2024
1 parent 0808df7 commit d5a8547
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions Sources/Client/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,8 @@ namespace spades {
HitBoxes hb = other.GetHitBoxes();
if (hb.head.RayCast(muzzle, dir, &hitPos)) {
float const dist = (hitPos - muzzle).GetLength2D();
if (!hitPlayer || dist < hitPlayerDist2D) {
if (!hitPlayer || dist < hitPlayerDist2D ||
(hitPart != HitBodyPart::Head && hitPart != HitBodyPart::Torso)) {
hitPlayer = other;
hitPlayerDist2D = dist;
hitPlayerDist3D = (hitPos - muzzle).GetLength();
Expand All @@ -565,14 +566,19 @@ namespace spades {

if (hb.torso.RayCast(muzzle, dir, &hitPos)) {
float const dist = (hitPos - muzzle).GetLength2D();
if (!hitPlayer || dist < hitPlayerDist2D) {
if (!hitPlayer || dist < hitPlayerDist2D ||
(hitPart != HitBodyPart::Head && hitPart != HitBodyPart::Torso)) {
hitPlayer = other;
hitPlayerDist2D = dist;
hitPlayerDist3D = (hitPos - muzzle).GetLength();
hitPart = HitBodyPart::Torso;
}
}

// check limbs only if no head or torso hit detected
if (hitPart == HitBodyPart::Head || hitPart == HitBodyPart::Torso)
continue;

for (int j = 0; j < 3; j++) {
if (hb.limbs[j].RayCast(muzzle, dir, &hitPos)) {
float const dist = (hitPos - muzzle).GetLength2D();
Expand Down Expand Up @@ -1233,34 +1239,37 @@ namespace spades {
float yaw = atan2f(o.y, o.x) + M_PI_F * 0.5F;
float pitch = -atan2f(o.z, o.GetLength2D());

float armPitch = pitch;
if (input.sprint)
armPitch -= 0.9F;
if (armPitch < 0.0F)
armPitch = std::max(armPitch, -M_PI_F * 0.5F) * 0.9F;

// lower axis
Matrix4 const lower = Matrix4::Translate(GetOrigin())
* Matrix4::Rotate(MakeVector3(0, 0, 1), yaw);
Matrix4 const torso = lower
* Matrix4::Translate(0, 0, -(input.crouch ? 0.55F : 1.0F));
Matrix4 const head = torso
* Matrix4::Rotate(MakeVector3(1, 0, 0), pitch);
Matrix4 const arms = torso
* Matrix4::Translate(0, 0, input.crouch ? 0.0F : 0.1F)
* Matrix4::Rotate(MakeVector3(1, 0, 0), armPitch);

if (input.crouch) {
hb.limbs[0] = AABB3(-0.4F, -0.1F, -0.2F, 0.3F, 0.4F, 0.8F);
hb.limbs[1] = AABB3(0.1F, -0.1F, -0.2F, 0.3F, 0.4F, 0.8F);
hb.torso = AABB3(-0.4F, -0.1F, -0.1F, 0.8F, 0.8F, 0.7F);
hb.limbs[2] = AABB3(-0.6F, -0.15F, -0.1F, 1.2F, 0.3F, 0.7F);
hb.head = AABB3(-0.3F, -0.3F, -0.6F, 0.6F, 0.6F, 0.6F);
hb.limbs[0] = lower * AABB3(-0.4F, -0.1F, -0.2F, 0.3F, 0.4F, 0.8F);
hb.limbs[1] = lower * AABB3(0.1F, -0.1F, -0.2F, 0.3F, 0.4F, 0.8F);
hb.torso = torso * AABB3(-0.4F, -0.1F, -0.1F, 0.8F, 0.8F, 0.7F);
hb.limbs[2] = arms * AABB3(-0.6F, -1.0F, -0.1F, 1.2F, 1.0F, 0.6F);
hb.head = head * AABB3(-0.3F, -0.3F, -0.6F, 0.6F, 0.6F, 0.6F);
} else {
hb.limbs[0] = AABB3(-0.4F, -0.2F, -0.15F, 0.3F, 0.4F, 1.2F);
hb.limbs[1] = AABB3(0.1F, -0.2F, -0.15F, 0.3F, 0.4F, 1.2F);
hb.torso = AABB3(-0.4F, -0.2F, 0.0F, 0.8F, 0.4F, 0.9F);
hb.limbs[2] = AABB3(-0.6F, -0.15F, 0.0F, 1.2F, 0.3F, 0.9F);
hb.head = AABB3(-0.3F, -0.3F, -0.6F, 0.6F, 0.6F, 0.6F);
hb.limbs[0] = lower * AABB3(-0.4F, -0.2F, -0.15F, 0.3F, 0.4F, 1.2F);
hb.limbs[1] = lower * AABB3(0.1F, -0.2F, -0.15F, 0.3F, 0.4F, 1.2F);
hb.torso = torso * AABB3(-0.4F, -0.2F, 0.0F, 0.8F, 0.4F, 0.9F);
hb.limbs[2] = arms * AABB3(-0.6F, -1.0F, -0.1F, 1.2F, 1.0F, 0.6F);
hb.head = head * AABB3(-0.3F, -0.3F, -0.6F, 0.6F, 0.6F, 0.6F);
}

hb.limbs[0] = lower * hb.limbs[0];
hb.limbs[1] = lower * hb.limbs[1];
hb.torso = torso * hb.torso;
hb.limbs[2] = torso * hb.limbs[2];
hb.head = head * hb.head;

return hb;
}

Expand Down

0 comments on commit d5a8547

Please sign in to comment.