BITFALL/Assets/Artists/Scripts/Feel/PlayerHitMotion.cs

33 lines
834 B
C#
Raw Normal View History

2023-10-20 19:31:12 +08:00
using System.Collections;
using System.Collections.Generic;
using BITKit.FPS;
using UnityEngine;
namespace BITKit.Entities.Player.Feel
{
2023-10-30 01:25:53 +08:00
public sealed class PlayerHitMotion : EntityBehavior
2023-10-20 19:31:12 +08:00
{
[SerializeField] private Spring3 spring;
[SerializeField] private LocationAdditive locationAdditive;
[SerializeField] private AnimationCurve damageBasedMotion;
public override void OnStart()
{
2023-10-30 01:25:53 +08:00
UnityEntity.AddListener<DamageMessage>(OnDamaged);
2023-10-20 19:31:12 +08:00
}
private void OnDamaged(DamageMessage obj)
{
2023-10-30 01:25:53 +08:00
if (obj.Target != UnityEntity) return;
2023-10-24 23:37:59 +08:00
var damage = damageBasedMotion.Evaluate(obj.Damage);
2023-10-20 19:31:12 +08:00
spring.value = new Vector3(damage.Random(), damage.Random(), damage.Random());
}
public override void OnUpdate(float deltaTime)
{
spring.Update(deltaTime,default);
locationAdditive.AddEuler(spring.value);
}
}
}