Jump to content

check where player was hurt


NqwSqw

Recommended Posts

This is actually kinda tricky but here is the general gist:

  • Create a list of AABB representing the player's body part hitboxes: the head, left leg, right leg, body, right arm, left arm.
  • Using the LivingHurtEvent or whatnot grab the player being hurt and the player initiating the attack.
  • Your attack vector is [attacker.eye] - [victim.eye] + [attacker.forward], or alternatively [attacker.forward] * [attacker.reach_distance]. Either should work but the second variant is preferrable.
  • Transform the attack vector into the AABB space(which is the forward-Z identity space). Basically do it by manually rotating the vector around the Y axis by the degrees between the [victim.forward] and [unitZ] vectors, and then do the same with the victim's pitch(not the head pitch, the body pitch). Or construct a transform matrix and multiply the vector by it, it works too. There are a lot of math papers on the subject that might help you here.
  • Now that you have the attack vector in AABB space simply check which boxes it intersects with - that's your hit bodypart. It may not intersect any though because of the way the game works.

You could also implement BB boxes(not Axis-Aligned) and work with them but it's a bit more tricky albeit a better solution. Again, there are a lot of papers on the topic of BBxes, you just need to search for them.

Unfortunately Iimplementing moving body parts like the legs and the arms is trickier since their transformations only exist on the client, so you would have to replicate them on the server in the even based on variables like swingProgress, but you might simply be lacking a few values which may or may not be important, then transform the vector to the space of animated body part and check whether it intersects that AABB. You only need to check that one AABB and you don't have to check it again. Do the same for all body parts.

That's how I would do it anyway.

Edited by V0idWa1k3r
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.