2y ago · Mar 16, 2024 1:40 PM
Most humanoid characters in Unity games utilize Unity's built-in component and enum.
How to read and connect skeletal joints in Unity C#:
CSHARP
Animator CSHARP
HumanBodyBonesHow to read and connect skeletal joints in Unity C#:
CSHARP
using UnityEngine;
public static class SkeletonESP
{
private static readonly (HumanBodyBones, HumanBodyBones)[] BoneConnections = new[]
{
// Spine & Head
(HumanBodyBones.Head, HumanBodyBones.Neck),
(HumanBodyBones.Neck, HumanBodyBones.Chest),
(HumanBodyBones.Chest, HumanBodyBones.Spine),
(HumanBodyBones.Spine, HumanBodyBones.Hips),
// Left Arm
(HumanBodyBones.Chest, HumanBodyBones.LeftShoulder),
(HumanBodyBones.LeftShoulder, HumanBodyBones.LeftUpperArm),
(HumanBodyBones.LeftUpperArm, HumanBodyBones.LeftLowerArm),
(HumanBodyBones.LeftLowerArm, HumanBodyBones.LeftHand),
// Right Arm
(HumanBodyBones.Chest, HumanBodyBones.RightShoulder),
(HumanBodyBones.RightShoulder, HumanBodyBones.RightUpperArm),
(HumanBodyBones.RightUpperArm, HumanBodyBones.RightLowerArm),
(HumanBodyBones.RightLowerArm, HumanBodyBones.RightHand),
// Left Leg
(HumanBodyBones.Hips, HumanBodyBones.LeftUpperLeg),
(HumanBodyBones.LeftUpperLeg, HumanBodyBones.LeftLowerLeg),
(HumanBodyBones.LeftLowerLeg, HumanBodyBones.LeftFoot),
// Right Leg
(HumanBodyBones.Hips, HumanBodyBones.RightUpperLeg),
(HumanBodyBones.RightUpperLeg, HumanBodyBones.RightLowerLeg),
(HumanBodyBones.RightLowerLeg, HumanBodyBones.RightFoot)
};
public static void DrawSkeleton(Animator animator, Camera camera, Color boneColor)
{
if (animator == null || !animator.isHuman) return;
foreach (var (boneA, boneB) in BoneConnections)
{
Transform tA = animator.GetBoneTransform(boneA);
Transform tB = animator.GetBoneTransform(boneB);
if (tA == null || tB == null) continue;
Vector3 sA = camera.WorldToScreenPoint(tA.position);
Vector3 sB = camera.WorldToScreenPoint(tB.position);
if (sA.z <= 0.01f || sB.z <= 0.01f) continue;
Vector2 screenA = new Vector2(sA.x, Screen.height - sA.y);
Vector2 screenB = new Vector2(sB.x, Screen.height - sB.y);
// Draw line between joint A and joint B
DrawLine(screenA, screenB, boneColor);
}
}
}
BoneMatrix_ · Source 2 Skeleton ESP & Hitboxes
The following users thanked BoneMatrix_ for this post: