Blockland Forums > Modification Help

Player::getDamageLocation

Pages: << < (2/2)

Val:

There was an old mod by Jookia (don't remember what) that ran each projectile hit through paintProjectile::onCollision, which calls ShapeBase::setTempColor, and it compared node colors before and after to determine what area was hit. It's clever, but limited by the fact setTempColor isn't as specific (i.e, left leg and right leg aren't unique).

The two other "hit region" mods I can think of are this and a random script by Port but both are fairly similar to what you made.

As far as a better solution goes, the "correct" way to do hit boxes/regions is by converting the world coordinates of an impact back to the target's model coordinates. To do this just do the reverse of what projection does in rasterization. An object's model coordinates are converted to world space by multiplying them by the object's transform (getTransform()), so to reverse this for a projectile impact in world space, you multiply that point by the inverse of the object's transform. I don't see any implementations of a matrix inverse function out there (besides ones that translate the homogeneous coordinates back to a 4x4 matrix, which is messy) so here's that:


--- Code: ---function MatrixInverse(%m)
{
    %inv_rot = vectorScale(getWords(%m, 3, 5), -1) SPC getWord(%m, 6);
    %inv_pos_mat = MatrixMultiply("0 0 0" SPC %inv_rot, %m);
   
    return vectorScale(getWords(%inv_pos_mat, 0, 2), -1) SPC %inv_rot;
}

--- End code ---

Then you simply do MatrixMulPoint(%inverse, %impact) and write some fun "is point in box" code. An easy way to get the boxes would be loading up a properly scaled player model in blender, since that's the model view!

Masterlegodude:

I think ny old Remmington 700 and Grunt Birthday Skull-esque death mods use Jookia's script to locate the head

It seemed kinda messy, but it worked, guess i now have a reason to go back and update them

Also, is it possible to detect the hands, feet, and pants using this method?

Rally:


--- Quote from: Masterlegodude on March 25, 2018, 06:54:41 PM ---Also, is it possible to detect the hands, feet, and pants using this method?

--- End quote ---

Pants would be easy, hands not so much. For the pants you'd just have to find the location on the z axis where it goes from torso to pants, and then adjust for player scale.

The problem with hands is that they are often animated, but the collision box is always the same. At that point, you'd have to check for the position's location on the forward-back vector (to determine if they are hitting the back or front of a raised arm) and also find out if that arm is raised.

Pages: << < (2/2)

Go to full version