F1F88 / Headlamp

NMRIH Headlamp
GNU Affero General Public License v3.0
1 stars 1 forks source link

[BUG]使用第三方模型开启头灯时,头灯的角度不正确 #1

Open Sanj1Ng opened 3 months ago

Sanj1Ng commented 3 months ago

使用 !models 替换皮肤时,有些皮肤会导致头灯的方向是歪的,不是正前方而是在视野的某个角落,有方法解决吗? Use! When models replace the skin, some of the skin will cause the headlamp to be tilted, not directly in front but in a corner of the field of vision, is there a solution?

F1F88 commented 3 months ago

You are right. When players use third-party character models to turn on their headlamps, the angle of the headlamp may not meet expectations.

Solution:

A simple solution is to: after creating the "env_projectedtexture" entity, do not bind it to the player's skeleton, but continuously get the player's position and angle using CreateTimer, OnGameFrame, and then modify the position and angle of "env_projectedtexture".

The advantage is: relatively simple to implement, with existing code implementations to refer to:

The downside is: there will be some delay in the follow-up of the headlamp when moving. To reduce the delay, you need to get and modify the angle more frequently, but this will also consume more CPU resources.

If I have time, I will consider making this plugin more widely applicable.

Translated by ChatGPT.




你是对的。当玩家使用第三方的人物模型开启头灯时,头灯的角度可能不符合预期

解决方案:

一个简单的解决方案是:在创建 "env_projectedtexture" 实体后,不再将其绑定到玩家骨骼,而是通过 CreateTimerOnGameFrame 不停的获取玩家位置、角度,然后修改 "env_projectedtexture" 的位置、角度。

优点是:实现相对简单,有已实现的代码可以参考:

缺点是:移动时头灯的跟随会有一些延迟。想要降低延迟就需要更频繁的获取、修改角度,但这也会消耗更多的 CPU 资源

如果有时间我会考虑让这个插件的适用性更广泛。

产生原因(备忘): 目前的方法是先创建一个'env_projectedtexture'实体

    int entity = CreateEntityByName("env_projectedtexture");

然后通过下面的代码将其绑定到玩家的头部

    // 与玩家 "Head" 绑定
    SetVariantString("!activator");
    AcceptEntityInput(entity, "SetParent", client);
    SetVariantString(light.attachment);     // Head
    AcceptEntityInput(entity, "SetParentAttachment");

最后再开启照明 "TurnOn",并传送到玩家所在的位置实现的

    AcceptEntityInput(entity, "TurnOn");

    TeleportEntity(entity, light.offset, light.rotation);

如果玩家模型的没有骨骼 - "Head",或者 "Head" 的位置、角度不正确,都可能导致传送后的 "env_projectedtexture" 偏离预期。包括切换武器时,也会使 "env_projectedtexture" 的角度偏离。

切换武器导致角度偏离,目前是通过监听玩家切换武器,根据切换后的持有武器修正角度的

// NMRIH 中玩家切换武器时可能导致光源角度偏移
// 此函数用于在玩家切换武器后修正光源角度
void NMRIH_Correction_Light_Rotation(int light_entity, int weapon)
{
    if( ! IsValidEntity(weapon) )
        return ;

    static char classname[32];
    GetEntityClassname(weapon, classname, sizeof(classname));

    if( NMRIH_IsGun(classname) || NMRIH_IsBowDeerHunter(classname))
    {
        if( NMRIH_IsHandGun(classname) )
        {
            TeleportEntity(light_entity, _, {20.0, -72.0, 0.0});
            return ;
        }
        TeleportEntity(light_entity, _, {25.6, -72.0, 0.0});
        return ;
    }

    // 信号枪、手电筒、MAC
    if( NMRIH_IsMaglite(classname) || NMRIH_IsFlareGun(classname) || NMRIH_IsMAC10(classname) )
    {
        TeleportEntity(light_entity, _, {20.0, -72.0, 0.0});
        return ;
    }

    TeleportEntity(light_entity, _, g_configs.light.rotation);
}
Sanj1Ng commented 2 months ago

You are right. When players use third-party character models to turn on their headlamps, the angle of the headlamp may not meet expectations.

你没看错,当玩家使用第三方角色模型打开大灯时,大灯的角度可能达不到预期。

Solution:

解决方案:

CreateTimer``OnGameFrame

CreateTimer``OnGameFrame

The advantage is: relatively simple to implement, with existing code implementations to refer to:

优点是:实现起来比较简单,可以参考现有的代码实现:

* https://forums.alliedmods.net/showthread.php?t=173257

* https://forums.alliedmods.net/showthread.php?t=173257

* https://forums.alliedmods.net/showthread.php?p=1720523

* https://forums.alliedmods.net/showthread.php?p=1720523

* https://github.com/LuxLuma/L4D-small-plugins/tree/master/L4D1-2_team_lights

* https://github.com/LuxLuma/L4D-small-plugins/tree/master/L4D1-2_team_lights

The downside is: there will be some delay in the follow-up of the headlamp when moving. To reduce the delay, you need to get and modify the angle more frequently, but this will also consume more CPU resources.

缺点是:移动时前照灯的跟进会有一些延迟。为了减少延迟,您需要更频繁地获取和修改角度,但这也会消耗更多的CPU资源。

If I have time, I will consider making this plugin more widely applicable.

如果我有时间,我会考虑让这个插件更广泛地适用。

Translated by ChatGPT.

由ChatGPT翻译。

你是对的。当玩家使用第三方的人物模型开启头灯时,头灯的角度可能不符合预期

你是对的。当玩家使用第三方的人物模型开启头灯时,头灯的角度可能不符合预期

解决方案:

解决方案:

CreateTimer``OnGameFrame

CreateTimer``OnGameFrame

优点是:实现相对简单,有已实现的代码可以参考:

优点是:实现相对简单,有已实现的代码可以参考:

* https://forums.alliedmods.net/showthread.php?t=173257

* https://forums.alliedmods.net/showthread.php?t=173257

* https://forums.alliedmods.net/showthread.php?p=1720523

* https://forums.alliedmods.net/showthread.php?p=1720523

* https://github.com/LuxLuma/L4D-small-plugins/tree/master/L4D1-2_team_lights

* https://github.com/LuxLuma/L4D-small-plugins/tree/master/L4D1-2_team_lights

缺点是:移动时头灯的跟随会有一些延迟。想要降低延迟就需要更频繁的获取、修改角度,但这也会消耗更多的 CPU 资源

缺点是:移动时头灯的跟随会有一些延迟。想要降低延迟就需要更频繁的获取、修改角度,但这也会消耗更多的 CPU 资源

如果有时间我会考虑让这个插件的适用性更广泛。

如果有时间我会考虑让这个插件的适用性更广泛。

产生原因(备忘):

产生原因(备忘):

    int entity = CreateEntityByName("env_projectedtexture");

然后通过下面的代码将其绑定到玩家的头部

然后通过下面的代码将其绑定到玩家的头部

    // 与玩家 "Head" 绑定
    SetVariantString("!activator");
    AcceptEntityInput(entity, "SetParent", client);
    SetVariantString(light.attachment);     // Head
    AcceptEntityInput(entity, "SetParentAttachment");

最后再开启照明 "TurnOn",并传送到玩家所在的位置实现的

最后再开启照明 "TurnOn",并传送到玩家所在的位置实现的

    AcceptEntityInput(entity, "TurnOn");

    TeleportEntity(entity, light.offset, light.rotation);

如果玩家模型的没有骨骼 - "Head",或者 "Head" 的位置、角度不正确,都可能导致传送后的 "env_projectedtexture" 偏离预期。包括切换武器时,也会使 "env_projectedtexture" 的角度偏离。

如果玩家模型的没有骨骼 - "Head",或者 "Head" 的位置、角度不正确,都可能导致传送后的 "env_projectedtexture" 偏离预期。包括切换武器时,也会使 "env_projectedtexture" 的角度偏离。

切换武器导致角度偏离,目前是通过监听玩家切换武器,根据切换后的持有武器修正角度的

切换武器导致角度偏离,目前是通过监听玩家切换武器,根据切换后的持有武器修正角度的

// NMRIH 中玩家切换武器时可能导致光源角度偏移
// 此函数用于在玩家切换武器后修正光源角度
void NMRIH_Correction_Light_Rotation(int light_entity, int weapon)
{
    if( ! IsValidEntity(weapon) )
        return ;

    static char classname[32];
    GetEntityClassname(weapon, classname, sizeof(classname));

    if( NMRIH_IsGun(classname) || NMRIH_IsBowDeerHunter(classname))
    {
        if( NMRIH_IsHandGun(classname) )
        {
            TeleportEntity(light_entity, _, {20.0, -72.0, 0.0});
            return ;
        }
        TeleportEntity(light_entity, _, {25.6, -72.0, 0.0});
        return ;
    }

    // 信号枪、手电筒、MAC
    if( NMRIH_IsMaglite(classname) || NMRIH_IsFlareGun(classname) || NMRIH_IsMAC10(classname) )
    {
        TeleportEntity(light_entity, _, {20.0, -72.0, 0.0});
        return ;
    }

    TeleportEntity(light_entity, _, g_configs.light.rotation);
}

好吧,期望大佬有时间可以改一个 :)