mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-22 03:53:04 +00:00
inflict damage based on part of body that was hit
This commit is contained in:
parent
b203a0b667
commit
f2c9e5ff75
6 changed files with 64 additions and 4 deletions
|
@ -448,8 +448,8 @@ MonoBehaviour:
|
|||
m_onDamage:
|
||||
m_PersistentCalls:
|
||||
m_Calls:
|
||||
- m_Target: {fileID: 114220037769542022}
|
||||
m_MethodName: HandleDamageByDefault
|
||||
- m_Target: {fileID: 114099438993920694}
|
||||
m_MethodName: OnDamaged
|
||||
m_Mode: 1
|
||||
m_Arguments:
|
||||
m_ObjectArgument: {fileID: 0}
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace SanAndreasUnity.Behaviours
|
|||
public class DamageInfo
|
||||
{
|
||||
public float amount = 0f;
|
||||
public Transform raycastHitTransform = null;
|
||||
public object data = null;
|
||||
}
|
||||
|
||||
|
|
|
@ -87,6 +87,21 @@ namespace SanAndreasUnity.Behaviours
|
|||
return pos;
|
||||
}
|
||||
|
||||
public void OnDamaged()
|
||||
{
|
||||
DamageInfo damageInfo = this.Damageable.LastDamageInfo;
|
||||
|
||||
float amount = this.PlayerModel.GetAmountOfDamageForBone(damageInfo.raycastHitTransform, damageInfo.amount);
|
||||
|
||||
this.Health -= amount;
|
||||
|
||||
if (this.Health <= 0)
|
||||
{
|
||||
Object.Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,12 @@ namespace SanAndreasUnity.Behaviours
|
|||
public float minCameraDistanceFromPed = 2f;
|
||||
public float maxCameraDistanceFromPed = 30f;
|
||||
|
||||
[Header("Damage")]
|
||||
|
||||
public float legAndArmDamageMultiplier = 0.8f;
|
||||
public float stomachAndChestDamageMultiplier = 1.0f;
|
||||
public float headDamageMultiplier = 4.0f;
|
||||
|
||||
[Header("Health bar")]
|
||||
|
||||
public bool displayHealthBarAbovePeds = false;
|
||||
|
|
|
@ -98,6 +98,8 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
public Transform Pelvis { get; private set; }
|
||||
|
||||
readonly Dictionary<Transform, int> m_damageLevelPerBones = new Dictionary<Transform, int>();
|
||||
|
||||
public class FrameAnimData
|
||||
{
|
||||
public Vector3 pos;
|
||||
|
@ -327,7 +329,8 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
void SetupRagdoll()
|
||||
{
|
||||
// maybe assign forward vector to be the same as Z axis ?
|
||||
|
||||
m_damageLevelPerBones.Clear();
|
||||
|
||||
RagdollBuilder rb = new RagdollBuilder
|
||||
{
|
||||
|
@ -353,6 +356,41 @@ namespace SanAndreasUnity.Behaviours
|
|||
// set layer
|
||||
this.RootFrame.gameObject.SetLayerRecursive(Ped.PedBoneLayerName);
|
||||
|
||||
// assign damage level for bones
|
||||
|
||||
Transform[] stomachAndChest = new Transform[] { this.RootFrame.transform, this.UpperSpine.transform };
|
||||
Transform[] legsAndHands = new Transform[] { this.L_Thigh, this.R_Thigh, this.L_Calf, this.R_Calf,
|
||||
this.L_Foot, this.R_Foot, this.LeftUpperArm, this.RightUpperArm, this.LeftForeArm, this.RightForeArm };
|
||||
Transform[] headAndJaw = new Transform[] { this.Head.transform, this.Jaw.transform };
|
||||
|
||||
foreach (var bone in stomachAndChest)
|
||||
{
|
||||
m_damageLevelPerBones[bone] = 2;
|
||||
}
|
||||
foreach (var bone in legsAndHands)
|
||||
{
|
||||
m_damageLevelPerBones[bone] = 1;
|
||||
}
|
||||
foreach (var bone in headAndJaw)
|
||||
{
|
||||
m_damageLevelPerBones[bone] = 3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public float GetAmountOfDamageForBone(Transform boneTransform, float baseDamageValue)
|
||||
{
|
||||
if (m_damageLevelPerBones.TryGetValue(boneTransform, out int damageLevel))
|
||||
{
|
||||
if (1 == damageLevel)
|
||||
return baseDamageValue * PedManager.Instance.legAndArmDamageMultiplier;
|
||||
if (2 == damageLevel)
|
||||
return baseDamageValue * PedManager.Instance.stomachAndChestDamageMultiplier;
|
||||
if (3 == damageLevel)
|
||||
return baseDamageValue * PedManager.Instance.headDamageMultiplier;
|
||||
}
|
||||
|
||||
return 0f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -635,7 +635,7 @@ namespace SanAndreasUnity.Behaviours
|
|||
}
|
||||
else
|
||||
{
|
||||
damageable.Damage( new DamageInfo() { amount = this.Damage } );
|
||||
damageable.Damage( new DamageInfo() { amount = this.Damage, raycastHitTransform = hit.transform } );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue