charging animation implemented
This commit is contained in:
parent
7148263214
commit
2a2f3bf040
@ -67,7 +67,7 @@ AnimatorStateTransition:
|
||||
m_TransitionDuration: 0.25
|
||||
m_TransitionOffset: 0
|
||||
m_ExitTime: 0.875
|
||||
m_HasExitTime: 1
|
||||
m_HasExitTime: 0
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
|
||||
@ -1235,7 +1235,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3062706309015911873}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalPosition: {x: 2.52, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@ -1255,7 +1255,7 @@ BoxCollider2D:
|
||||
m_IsTrigger: 1
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: 1.7083191, y: 0}
|
||||
m_Offset: {x: -0.1805121, y: 0}
|
||||
m_SpriteTilingProperty:
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
pivot: {x: 0, y: 0}
|
||||
@ -1266,7 +1266,7 @@ BoxCollider2D:
|
||||
adaptiveTiling: 0
|
||||
m_AutoTiling: 0
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 0.5, y: 0.5}
|
||||
m_Size: {x: 0.6224893, y: 0.5}
|
||||
m_EdgeRadius: 0
|
||||
--- !u!114 &5850107427616902080
|
||||
MonoBehaviour:
|
||||
@ -2776,7 +2776,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 9048754633958631738}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalPosition: {x: -0.33, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@ -2796,7 +2796,7 @@ BoxCollider2D:
|
||||
m_IsTrigger: 1
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: 1, y: 0}
|
||||
m_Offset: {x: 1.33, y: 0}
|
||||
m_SpriteTilingProperty:
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
pivot: {x: 0, y: 0}
|
||||
|
||||
@ -19,9 +19,10 @@ public class Rider : Ally
|
||||
[SerializeField]
|
||||
private GameObject _root;
|
||||
|
||||
private Detection _chargeDetectionScript;
|
||||
private Root _rootScript;
|
||||
private Detection _detectionScript;
|
||||
|
||||
private int _originalAttackDamage;
|
||||
private Vector3 _originalPos;
|
||||
private Vector2 _movementVector = Vector2.zero;
|
||||
private bool _isCharging;
|
||||
@ -32,33 +33,37 @@ public class Rider : Ally
|
||||
{
|
||||
base.Start();
|
||||
|
||||
_chargeDetectionScript = _chargeDetection.GetComponent<Detection>();
|
||||
_rootScript = _root.GetComponent<Root>();
|
||||
_detectionScript = _detection.GetComponent<Detection>();
|
||||
|
||||
_originalAttackDamage = _chargeAttackDamage;
|
||||
_originalPos = transform.position;
|
||||
_isCharging = true;
|
||||
|
||||
_timeSinceLastCharge = _chargeCooldown + 1;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
|
||||
// check for charge cooldown
|
||||
if (_timeSinceLastCharge > _chargeCooldown)
|
||||
if (_timeSinceLastCharge > _chargeCooldown && !_isCharging)
|
||||
{
|
||||
SweepAttack();
|
||||
|
||||
_isCharging = true;
|
||||
Animation.ToggleChargeAnim(true);
|
||||
}
|
||||
|
||||
if (_isCharging)
|
||||
{
|
||||
SweepAttack();
|
||||
|
||||
// toggle charge detection
|
||||
_detection.SetActive(false);
|
||||
_chargeDetection.SetActive(true);
|
||||
|
||||
// movement
|
||||
_movementVector.x = Time.deltaTime * Speed;
|
||||
transform.position += (Vector3)_movementVector;
|
||||
|
||||
Debug.Log(IsEnemyDetected);
|
||||
// attack
|
||||
if (IsEnemyDetected && !_opponentsHit.Contains(Enemy))
|
||||
{
|
||||
@ -81,6 +86,9 @@ public class Rider : Ally
|
||||
IsEnemyDetected = false;
|
||||
Enemy = null;
|
||||
|
||||
// toggle animation
|
||||
Animation.ToggleChargeAnim(false);
|
||||
|
||||
// toggle detection
|
||||
_detection.SetActive(true);
|
||||
_chargeDetection.SetActive(false);
|
||||
@ -96,21 +104,39 @@ public class Rider : Ally
|
||||
}
|
||||
}
|
||||
|
||||
void AttackEnemyRiding()
|
||||
// attacks all enemies already in the default detection box at start of the charge.
|
||||
// charge uses a different detection due to Enemy being the oldest opponent to enter the hitbox.
|
||||
// therefore enemies would only get hit when the previous Enemy exits, which is at the handle instead of the tip`.
|
||||
// to cover for the enemies behind the charge detection which is at the tip, we hit them all as the charge starts
|
||||
private void SweepAttack()
|
||||
{
|
||||
Debug.Log("Attack Riding");
|
||||
_rootScript.AttackWithCustomDamage(_chargeAttackDamage);
|
||||
foreach (Entity entity in _detectionScript.DetectedEntities)
|
||||
{
|
||||
Enemy = entity;
|
||||
AttackEnemyRiding();
|
||||
}
|
||||
if (_detectionScript.DetectedEntities.Count > 0)
|
||||
{
|
||||
_detection.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void AttackEnemyRiding()
|
||||
{
|
||||
AttackDamage = _chargeAttackDamage;
|
||||
_rootScript.Attack();
|
||||
_opponentsHit.Add(Enemy);
|
||||
}
|
||||
|
||||
void AttackEnemy()
|
||||
private void AttackEnemy()
|
||||
{
|
||||
//Attack Cooldown
|
||||
if (AttackSpeedWait > AttackInterval)
|
||||
{
|
||||
|
||||
AttackDamage = _originalAttackDamage;
|
||||
Animation.PlayAttackAnim();
|
||||
|
||||
|
||||
AttackSpeedWait = 0f;
|
||||
}
|
||||
|
||||
|
||||
@ -9,7 +9,8 @@ public class AnimationEntity : MonoBehaviour
|
||||
Idle = 0,
|
||||
Walking = 1,
|
||||
Attacking = 2,
|
||||
Dying = 3
|
||||
Dying = 3,
|
||||
Charging = 4
|
||||
}
|
||||
private EntityAnimationState entityState;
|
||||
|
||||
@ -49,7 +50,8 @@ public class AnimationEntity : MonoBehaviour
|
||||
|
||||
public void PlayIdleAnim()
|
||||
{
|
||||
if(!_isDead) {
|
||||
if (!_isDead)
|
||||
{
|
||||
_animatorEntity.speed = 1;
|
||||
_animatorEntity.Play("idle", 0, 0f);
|
||||
entityState = EntityAnimationState.Idle;
|
||||
@ -58,7 +60,8 @@ public class AnimationEntity : MonoBehaviour
|
||||
|
||||
public void PlayWalkAnim()
|
||||
{
|
||||
if(!_isDead) {
|
||||
if (!_isDead)
|
||||
{
|
||||
_animatorEntity.speed = SpeedMultiplier;
|
||||
_animatorEntity.Play("walk", 0, 0f);
|
||||
entityState = EntityAnimationState.Walking;
|
||||
@ -68,7 +71,8 @@ public class AnimationEntity : MonoBehaviour
|
||||
|
||||
public void PlayAttackAnim()
|
||||
{
|
||||
if(!_isDead && _animatorEntity != null) {
|
||||
if (!_isDead && _animatorEntity != null)
|
||||
{
|
||||
_animatorEntity.speed = AttackSpeedMultiplier;
|
||||
_animatorEntity.Play("attack", 0, 0f);
|
||||
entityState = EntityAnimationState.Attacking;
|
||||
@ -76,6 +80,23 @@ public class AnimationEntity : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void ToggleChargeAnim(bool isCharging)
|
||||
{
|
||||
if (!_isDead && _animatorEntity != null)
|
||||
{
|
||||
_animatorEntity.speed = AttackSpeedMultiplier;
|
||||
_animatorEntity.SetBool("Charging", isCharging);
|
||||
if (isCharging)
|
||||
{
|
||||
entityState = EntityAnimationState.Charging;
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayIdleAnim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayDieAnim()
|
||||
{
|
||||
// Not every entity needs an animator
|
||||
|
||||
@ -178,4 +178,5 @@ public class Detection : MonoBehaviour
|
||||
return rect;
|
||||
}
|
||||
}
|
||||
public List<Entity> DetectedEntities { get { return detectedEntities; } }
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ public abstract class Entity : LevelObject
|
||||
renderer.color = currentColor;
|
||||
}
|
||||
|
||||
if(_spriteRenderers[0].color.a > 0f)
|
||||
if (_spriteRenderers[0].color.a > 0f)
|
||||
{
|
||||
Invoke("Dying", 0.1f);
|
||||
}
|
||||
@ -75,7 +75,7 @@ public abstract class Entity : LevelObject
|
||||
//When hit : get damage and start a flash of light
|
||||
public void Hit(int damage)
|
||||
{
|
||||
_hp-=damage;
|
||||
_hp -= damage;
|
||||
|
||||
_lifeBar.value = _hp / (float)_maxHp;
|
||||
|
||||
@ -100,7 +100,7 @@ public abstract class Entity : LevelObject
|
||||
|
||||
public void Move()
|
||||
{
|
||||
if(!_animation.IsWalking)
|
||||
if (!_animation.IsWalking)
|
||||
{
|
||||
_animation.PlayWalkAnim();
|
||||
}
|
||||
@ -123,7 +123,11 @@ public abstract class Entity : LevelObject
|
||||
|
||||
public float Speed => _speed * SpeedMultiplier;
|
||||
|
||||
public int AttackDamage => (int)(_attack_damage * DamageMultiplier);
|
||||
public int AttackDamage
|
||||
{
|
||||
get { return (int)(_attack_damage * DamageMultiplier); }
|
||||
set { _attack_damage = value; }
|
||||
}
|
||||
|
||||
public float AttackInterval => _attack_interval / AttackSpeedMultiplier;
|
||||
|
||||
|
||||
@ -24,18 +24,6 @@ public class Root : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void AttackWithCustomDamage(int damage)
|
||||
{
|
||||
if (_entity == null || _entity.Enemy == null) return;
|
||||
|
||||
_entity.Enemy.Hit(damage);
|
||||
if (_entity.Enemy.Hp <= 0)
|
||||
{
|
||||
_entity.Enemy.Death();
|
||||
_entity.IsEnemyDetected = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void ShotProjectile()
|
||||
{
|
||||
Rigidbody2D _rigidbodyAlly;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user