mirror of
https://github.com/creazy231/cs2-css-flashlight.git
synced 2026-09-27 20:17:04 +02:00
🔦 Fix flashlight beam not tracking view pitch
The light was positioned once at toggle time and then handed to the engine via SetParent + SetParentAttachmentMaintainOffset on the pawn's `axis_of_intent` attachment. That attachment carries the body's yaw but not the view pitch, so once parented the beam could only ever rotate horizontally — looking up or down did nothing. Drop the parenting and drive the light's transform ourselves every tick from the pawn's live AbsOrigin and V_angle, which is how the plugin behaved before 0.1.1 replaced the per-tick teleport with a parented entity. Also: - OnTick no longer short-circuits on !AllowUseKey, which otherwise stopped the light updating for servers that only expose css_fl_toggle. - ForwardDistance now offsets the light horizontally only. Applying it along the pitched forward vector put the light below ground when looking straight down (crouched eye height 46 minus 54). - Sweep up the light when the pawn is dead; an un-parented entity no longer dies with its pawn. - Remove the now-unused AttachmentName config key. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
b3bbc2dc9a
commit
b43f9fdea3
5 changed files with 217 additions and 48 deletions
|
|
@ -2,6 +2,12 @@ using System.Numerics;
|
|||
|
||||
namespace Flashlight;
|
||||
|
||||
/// <summary>
|
||||
/// Position and orientation to apply to the flashlight entity.
|
||||
/// <paramref name="Angles"/> is a Source QAngle laid out as (pitch, yaw, roll).
|
||||
/// </summary>
|
||||
public readonly record struct LightTransform(Vector3 Origin, Vector3 Angles);
|
||||
|
||||
public static class FlashlightLogic
|
||||
{
|
||||
public static bool TryToggle(ref bool isOn, ref bool canToggle)
|
||||
|
|
@ -50,6 +56,39 @@ public static class FlashlightLogic
|
|||
-MathF.Sin(pitchRad));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Forward vector on the horizontal plane only, ignoring pitch.
|
||||
/// </summary>
|
||||
public static Vector3 HorizontalForwardFromYawDegrees(float yaw)
|
||||
{
|
||||
var yawRad = yaw * (MathF.PI / 180f);
|
||||
|
||||
return new Vector3(MathF.Cos(yawRad), MathF.Sin(yawRad), 0f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// World transform for the flashlight given the player's current pawn origin and view angles.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The angles carry the full view rotation so the beam tracks pitch as well as yaw, while the
|
||||
/// origin is only pushed forward on the horizontal plane. Offsetting the origin along the full
|
||||
/// pitched forward vector would drop the light through the floor when looking straight down
|
||||
/// (a crouched eye height of 46 minus a 54 unit offset ends up below the ground).
|
||||
/// </remarks>
|
||||
public static LightTransform CalculateLightTransform(
|
||||
Vector3 pawnOrigin,
|
||||
float pitch,
|
||||
float yaw,
|
||||
float roll,
|
||||
float eyeOffsetZ,
|
||||
float forwardDistance)
|
||||
{
|
||||
var forward = HorizontalForwardFromYawDegrees(yaw);
|
||||
var origin = CalculateLightOrigin(pawnOrigin, forward, eyeOffsetZ, forwardDistance);
|
||||
|
||||
return new LightTransform(origin, new Vector3(pitch, yaw, roll));
|
||||
}
|
||||
|
||||
public static bool ShouldCreateLight(bool isOn, bool hasValidLight)
|
||||
{
|
||||
return isOn && !hasValidLight;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue