Initial commit: Tiny Tackle Heroes Unity project
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
using UnityEngine;
|
||||
using BumpCombat.Constants;
|
||||
|
||||
namespace BumpCombat.Combat
|
||||
{
|
||||
public static class BumpCombatMath
|
||||
{
|
||||
public static float FrontThreshold => GameplayConstants.Current.Combat.FrontThreshold;
|
||||
public static float BackThreshold => GameplayConstants.Current.Combat.BackThreshold;
|
||||
public static float PositionDamageMultiplier =>
|
||||
GameplayConstants.Current.Combat.PositionDamageMultiplier;
|
||||
public static float BackDamageMultiplier =>
|
||||
GameplayConstants.Current.Combat.BackDamageMultiplier;
|
||||
|
||||
public static HitSide ClassifySide(Vector2 enemyFacing, Vector2 enemyToPlayer)
|
||||
{
|
||||
float dot = Vector2.Dot(enemyFacing.normalized, enemyToPlayer.normalized);
|
||||
if (dot >= FrontThreshold)
|
||||
{
|
||||
return HitSide.Front;
|
||||
}
|
||||
|
||||
if (dot <= BackThreshold)
|
||||
{
|
||||
return HitSide.Back;
|
||||
}
|
||||
|
||||
return HitSide.Side;
|
||||
}
|
||||
|
||||
public static float CalculateLateralOffset(
|
||||
Vector2 attackDirection,
|
||||
Vector2 attackerPosition,
|
||||
Vector2 targetPosition)
|
||||
{
|
||||
if (attackDirection.sqrMagnitude <= 0f)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
|
||||
Vector2 direction = attackDirection.normalized;
|
||||
Vector2 perpendicular = new(-direction.y, direction.x);
|
||||
return Mathf.Abs(Vector2.Dot(
|
||||
targetPosition - attackerPosition,
|
||||
perpendicular));
|
||||
}
|
||||
|
||||
public static bool IsOffsetHit(
|
||||
HitSide side,
|
||||
Vector2 attackDirection,
|
||||
Vector2 attackerPosition,
|
||||
Vector2 targetPosition,
|
||||
float minimumLateralOffset)
|
||||
{
|
||||
return side == HitSide.Front
|
||||
&& CalculateLateralOffset(
|
||||
attackDirection,
|
||||
attackerPosition,
|
||||
targetPosition) >= minimumLateralOffset;
|
||||
}
|
||||
|
||||
public static float ApplySideMultiplier(
|
||||
float baseDamage,
|
||||
HitSide side,
|
||||
bool isOffsetHit = false)
|
||||
{
|
||||
float multiplier = side == HitSide.Back
|
||||
? BackDamageMultiplier
|
||||
: side == HitSide.Side || isOffsetHit
|
||||
? PositionDamageMultiplier
|
||||
: 1f;
|
||||
return DamageCalculator.ApplyMultiplier(baseDamage, multiplier);
|
||||
}
|
||||
|
||||
public static bool AppliesPlayerImpactRecoil(
|
||||
HitSide side,
|
||||
bool isEventEnemy = false)
|
||||
{
|
||||
return side != HitSide.Back || isEventEnemy;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user