Skip to content

Commit

Permalink
Add additionaø hitmarker effect on dealdamage
Browse files Browse the repository at this point in the history
  • Loading branch information
Fueredoriku committed Sep 16, 2024
1 parent 2c5c609 commit b112a6e
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Assets/Scripts/Gamestate/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ public virtual void SetGun(Transform offset)
gunController.onFireEnd += UpdateHudFire;
gunController.onReload += UpdateHudReload;
UpdateHudCrosshair(gunController.stats);
gunController.projectile.OnHitboxCollision += hudController.HitmarkAnimation;
gunController.projectile.OnHitboxCollision += hudController.HitAnimation;
}
playerIK.LeftHandIKTarget = gunController.LeftHandTarget;
if (gunController.RightHandTarget)
Expand Down
4 changes: 4 additions & 0 deletions Assets/Scripts/HitboxController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ public void DamageCollider(DamageInfo info)
if (!health.enabled)
return;
health?.DealDamage(info);

if (info.sourcePlayer != null)
if (info.sourcePlayer.HUDController != null)
info.sourcePlayer.HUDController.DamageAnimation();
}
}
22 changes: 19 additions & 3 deletions Assets/Scripts/UI/PlayerHUDController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public class PlayerHUDController : MonoBehaviour
[SerializeField]
private RectTransform scopeZoom;
private int scopeTween;
private int hitTween;
private int hitMarkTween;

private void Awake()
Expand Down Expand Up @@ -327,21 +328,36 @@ public void MoveCrosshair(float x, float y)
crosshair.rectTransform.anchoredPosition = (new Vector2(halfWidth * x, halfHeight * y));
}

public void HitmarkAnimation(HitboxController other, ref ProjectileState state)
public void HitAnimation(HitboxController other, ref ProjectileState state)
{
if (LeanTween.isTweening(hitTween))
{
LeanTween.cancel(hitTween);
SetCrossScale(crosshairCrossScale);
}
hitTween = LeanTween.value(crosshair.gameObject, SetCrossScale, crosshairCrossScale, 2.5f, 0.4f).setEasePunch().id;
}

public void DamageAnimation()
{
if (LeanTween.isTweening(hitMarkTween))
{
LeanTween.cancel(hitMarkTween);
SetCrossScale(crosshairCrossScale);
SetHitScale(0f);
}
hitMarkTween = LeanTween.value(crosshair.gameObject, SetCrossScale, crosshairCrossScale, 5f, 0.2f).setEasePunch().id;
hitMarkTween = LeanTween.value(crosshair.gameObject, SetHitScale, 0f, 1.5f, 0.2f).setEasePunch().id;
}

private void SetCrossScale(float scale)
{
crosshairMaterial.SetFloat("_CrossSize", scale);
}

private void SetHitScale(float scale)
{
crosshairMaterial.SetFloat("_HitMarkerRadius", scale);
}

public void UpdateOnInitialize(float radius)
{
crosshairMaterial.SetFloat("_Radius", radius == 0f ? 1f : 1f/radius);
Expand Down
10 changes: 8 additions & 2 deletions Assets/Shaders/CrossHair.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ float sdCross_float( in float2 p, in float2 b, float r )
return sign(k)*length(max(w,0.0)) + r;
}

float sdRoundedX_float( float2 p, float w, float r )
{
p = abs(p);
return max(length(p-min(p.x+p.y,w)*0.5) - r, -1. * (length(p) - 0.5));
}

float crossSDF_float(float2 pos)
{
return abs(sdCross_float(pos, float2(0.5, 0.1), 0.1))-0.05;
}


void CrossHair_float(float2 UV, float crossSize, float circleRadius, out float Distance)
void CrossHair_float(float2 UV, float crossSize, float circleRadius, float hitMarkerRadius, out float Distance)
{
Distance = min(sphereSDF_float(UV * 2.5 * circleRadius), crossSDF_float(UV * crossSize));
Distance = min(min(sphereSDF_float(UV * 2.5 * circleRadius), crossSDF_float(UV * crossSize)), sdRoundedX_float(UV, hitMarkerRadius, 0.1));
}
130 changes: 125 additions & 5 deletions Assets/Shaders/Crosshair.shadergraph
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
},
{
"m_Id": "39003c110ecc4efeb92e0a4f81adf62c"
},
{
"m_Id": "187b92def2fb4ca685fae44d6a779b0d"
}
],
"m_Keywords": [],
Expand Down Expand Up @@ -62,6 +65,9 @@
},
{
"m_Id": "20d6ebc89b914b0c83d3f8b1fe771ce0"
},
{
"m_Id": "69ee95579277414b976cc4f92ccee9b9"
}
],
"m_GroupDatas": [],
Expand Down Expand Up @@ -137,6 +143,20 @@
"m_SlotId": 0
}
},
{
"m_OutputSlot": {
"m_Node": {
"m_Id": "69ee95579277414b976cc4f92ccee9b9"
},
"m_SlotId": 0
},
"m_InputSlot": {
"m_Node": {
"m_Id": "ef5bd6ae10c045938b52ca9c8926f784"
},
"m_SlotId": 4
}
},
{
"m_OutputSlot": {
"m_Node": {
Expand Down Expand Up @@ -397,6 +417,49 @@
}
}

{
"m_SGVersion": 1,
"m_Type": "UnityEditor.ShaderGraph.Internal.Vector1ShaderProperty",
"m_ObjectId": "187b92def2fb4ca685fae44d6a779b0d",
"m_Guid": {
"m_GuidSerialized": "6591cd6f-f50c-4106-ab48-fb325aae5d86"
},
"m_Name": "HitMarkerRadius",
"m_DefaultRefNameVersion": 1,
"m_RefNameGeneratedByDisplayName": "HitMarkerRadius",
"m_DefaultReferenceName": "_HitMarkerRadius",
"m_OverrideReferenceName": "",
"m_GeneratePropertyBlock": true,
"m_UseCustomSlotLabel": false,
"m_CustomSlotLabel": "",
"m_DismissedVersion": 0,
"m_Precision": 0,
"overrideHLSLDeclaration": false,
"hlslDeclarationOverride": 0,
"m_Hidden": false,
"m_Value": 0.0,
"m_FloatType": 0,
"m_RangeValues": {
"x": 0.0,
"y": 1.0
}
}

{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "1884236d1166428caab304ddc7d5033f",
"m_Id": 4,
"m_DisplayName": "HitMarkerRadius",
"m_SlotType": 0,
"m_Hidden": false,
"m_ShaderOutputName": "HitMarkerRadius",
"m_StageCapability": 3,
"m_Value": 0.0,
"m_DefaultValue": 0.0,
"m_Labels": []
}

{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.DynamicValueMaterialSlot",
Expand Down Expand Up @@ -546,10 +609,10 @@
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -258.3999938964844,
"y": 171.1999969482422,
"width": 208.0,
"height": 301.60003662109377
"x": -130.3999481201172,
"y": 220.79998779296876,
"width": 130.40000915527345,
"height": 117.60000610351563
}
},
"m_Slots": [
Expand All @@ -569,7 +632,7 @@
"x"
],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_PreviewExpanded": false,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
Expand Down Expand Up @@ -932,6 +995,42 @@
}
}

{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.PropertyNode",
"m_ObjectId": "69ee95579277414b976cc4f92ccee9b9",
"m_Group": {
"m_Id": ""
},
"m_Name": "Property",
"m_DrawState": {
"m_Expanded": true,
"m_Position": {
"serializedVersion": "2",
"x": -1315.199951171875,
"y": 680.0,
"width": 162.39990234375,
"height": 33.60003662109375
}
},
"m_Slots": [
{
"m_Id": "d6b4d29cc5614f9ea88c973e85d9c9b7"
}
],
"synonyms": [],
"m_Precision": 0,
"m_PreviewExpanded": true,
"m_DismissedVersion": 0,
"m_PreviewMode": 0,
"m_CustomColors": {
"m_SerializableColors": []
},
"m_Property": {
"m_Id": "187b92def2fb4ca685fae44d6a779b0d"
}
}

{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot",
Expand Down Expand Up @@ -1352,6 +1451,9 @@
},
{
"m_Id": "39003c110ecc4efeb92e0a4f81adf62c"
},
{
"m_Id": "187b92def2fb4ca685fae44d6a779b0d"
}
]
}
Expand Down Expand Up @@ -1558,6 +1660,21 @@
}
}

{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
"m_ObjectId": "d6b4d29cc5614f9ea88c973e85d9c9b7",
"m_Id": 0,
"m_DisplayName": "HitMarkerRadius",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "Out",
"m_StageCapability": 3,
"m_Value": 0.0,
"m_DefaultValue": 0.0,
"m_Labels": []
}

{
"m_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot",
Expand Down Expand Up @@ -1640,6 +1757,9 @@
{
"m_Id": "a979b08289834e069512937ffd2faf6c"
},
{
"m_Id": "1884236d1166428caab304ddc7d5033f"
},
{
"m_Id": "1fe619ab1c344729b4f4c7f0eb3fade3"
}
Expand Down

0 comments on commit b112a6e

Please sign in to comment.