#Trying to get hitbox of bodypart from player using raycast

1 messages · Page 1 of 1 (latest)

hasty kettle
#

I tried to see how it could be done, but I have no explanation when I looked at NW code how they did it, it was even more confusing so yea

#

I've tried raycast.Value.collider.gameObject.GetComponent<HitboxIdentity>();

#

Trying to get hitbox of bodypart from player using raycast

hasty kettle
#

I've did it

#

just need to raycast for hitbox layermask and not all layermask

#

[YE] Trying to get hitbox of bodypart from player using raycast

#

[ANSWERED] Trying to get hitbox of bodypart from player using raycast

hasty kettle
#

I was very wrong it did not work

#

Trying to get hitbox of bodypart from player using raycast

normal forum
#

I'm pretty sure just raycast.Value.collider is the actual hitbox of whatever the collider collided with

hasty kettle
#

wait I haven't tried logging the collider itself only gameObject

#

I'll try it

#

Collider: Player(Clone) (UnityEngine.CharacterController)

mighty yacht
#

This would be a bit of a safer way to do it

#

Of course you'd want to log before the returns so you get the right info

hasty kettle
#

what a legend

mighty yacht
#

Anything for you @hasty kettle ;)

#

Haha

hasty kettle
#

TheGuy has this method that would be good to be added

mighty yacht
#

If you're cool and like Harmony patches

#
[HarmonyPatch(typeof(HitscanResult), nameof(HitscanResult.RegisterDamage))]
public class LogHitbox : CustomItemBase<LogHitbox>
{
    protected internal override string Name => "LogHitbox";
    protected internal override Rarity Rarity => Rarity.Custom;
    protected internal override string Description => "Debug thing";
    protected internal override ItemType ItemType => ItemType.GunCOM18;
    protected internal override Color PickupLightColor => Color.white;

    public static void Prefix(IDestructible dest, ref float appliedDamage, AttackerDamageHandler handler)
    {
        if (handler is not FirearmDamageHandler dh ||
            dest is not HitboxIdentity identity ||
            !CustomItemData.ContainsKey(dh.Firearm.ItemSerial))
            return;
        
        Logger.Info(identity.name);
        appliedDamage *= 0.5f;
    }
}
#

Something I whipped up

#

The relevant bit is

[HarmonyPatch(typeof(HitscanResult), nameof(HitscanResult.RegisterDamage))]
public class FirearmStuff
{
    private static bool Check(ushort firearmSerial) => true; // If this is true, run the half damage code
    public static void Prefix(IDestructible dest, ref float appliedDamage, AttackerDamageHandler handler)
    {
        if (handler is not FirearmDamageHandler dh ||
            dest is not HitboxIdentity identity ||
            !Check(firearmSerial))
            return;
        
        Logger.Info(identity.name); // The name of the body part you're hitting
        appliedDamage *= 0.5f; // Changing the applied damage, not necessary but it's a typical example of what you'd use this kind of thing for
    }
}
#

@ashen kettle I know you said no Harmony patches but they really are a useful tool, and this is something that'd work for your purposes, and would prevent the need to do double raycasts every time a person shoots a weapon (unnecessary server load)

#

Might actually be a noticeable performance improvement when handling larger gun fights

#

Raycasts tend to be decently expensive

ashen kettle
#

Yeah

mighty yacht
#

Especially because the game runs on a single thread

ashen kettle
#

I'm not using patches because I just don't know how to do that, no tutorial ever worked and I just kinda gave up on them

mighty yacht
#

They're pretty easy, there's just not a lot of good resources out there

#

Let me send you the site I look at for docs

#

Pretty good stuff

ashen kettle
#

Figured, been trying to learn but when all I see is 40 lines of instructions I feel like there's a more obscure reason hid in the game files that I actually understand

#

Rather than patching I've just publicized my assembly csharp and did everything using that

mighty yacht
mighty yacht
#

Publicizing is good for avoiding needing reflection

#

Not necessarily avoiding patching

ashen kettle
#

Anyway

#

do you know

#

how the game handles item animations?

#

Cuz' I've been trying to force one but I can't seem to find anything that actually plays the animation

mighty yacht
ashen kettle
mighty yacht
#

That only works if animations are handled by network messages, but I don't believe they are

#

Fake syncing is the server telling the client something that isn't true

#

The server knows it's one thing, but tells the client another

ashen kettle
#

@mighty yacht could you check your dms?