Adds knight on horse and its animations #8

Merged
Garutako merged 16 commits from art/knightOnHorse into main 2025-07-14 22:58:23 +00:00
4 changed files with 45 additions and 11 deletions
Showing only changes of commit 228e16b2b4 - Show all commits

View File

@ -36,7 +36,7 @@ AnimatorController:
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 9100000} m_Controller: {fileID: 0}
m_AnimatorLayers: m_AnimatorLayers:
- serializedVersion: 5 - serializedVersion: 5
m_Name: Base Layer m_Name: Base Layer

View File

@ -1118,11 +1118,13 @@ MonoBehaviour:
_attack_damage: 3 _attack_damage: 3
_attack_interval: 2 _attack_interval: 2
_enemy: {fileID: 0} _enemy: {fileID: 0}
_chargeAttackDamage: 5
_chargeCooldown: 5
_maxChargeHitCount: 3
_maxChargeDistance: 10
_detection: {fileID: 9048754633958631738} _detection: {fileID: 9048754633958631738}
_chargeDetection: {fileID: 4280547952316628076} _chargeDetection: {fileID: 4280547952316628076}
_root: {fileID: 2230360378127571586} _root: {fileID: 2230360378127571586}
_maxChargeHitCount: 3
_maxChargeDistance: 10
--- !u!1839735485 &3032268583489863936 --- !u!1839735485 &3032268583489863936
Tilemap: Tilemap:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -4,23 +4,29 @@ using UnityEngine;
public class Rider : Ally public class Rider : Ally
{ {
[SerializeField]
private int _chargeAttackDamage;
[SerializeField]
private int _chargeCooldown;
[SerializeField]
private int _maxChargeHitCount;
[SerializeField]
private int _maxChargeDistance;
[SerializeField] [SerializeField]
private GameObject _detection; private GameObject _detection;
[SerializeField] [SerializeField]
private GameObject _chargeDetection; private GameObject _chargeDetection;
private Detection _chargeDetectionScript;
[SerializeField] [SerializeField]
private GameObject _root; private GameObject _root;
private Detection _chargeDetectionScript;
private Root _rootScript; private Root _rootScript;
private Vector3 _originalPos;
private Vector2 _movementVector = Vector2.zero; private Vector2 _movementVector = Vector2.zero;
private bool _isCharging; private bool _isCharging;
[SerializeField] private float _timeSinceLastCharge;
private int _maxChargeHitCount;
private List<Entity> _opponentsHit = new List<Entity>(); private List<Entity> _opponentsHit = new List<Entity>();
[SerializeField]
private int _maxChargeDistance;
private Vector3 _originalPos;
public override void Start() public override void Start()
{ {
@ -35,8 +41,15 @@ public class Rider : Ally
public override void Update() public override void Update()
{ {
// check for charge cooldown
if (_timeSinceLastCharge > _chargeCooldown)
{
_isCharging = true;
}
if (_isCharging) if (_isCharging)
{ {
// toggle charge detection
_detection.SetActive(false); _detection.SetActive(false);
_chargeDetection.SetActive(true); _chargeDetection.SetActive(true);
@ -53,20 +66,27 @@ public class Rider : Ally
// reset // reset
if (transform.position.x - _originalPos.x >= _maxChargeDistance || _opponentsHit.Count >= _maxChargeHitCount) if (transform.position.x - _originalPos.x >= _maxChargeDistance || _opponentsHit.Count >= _maxChargeHitCount)
{ {
_isCharging = false; // position
_movementVector = Vector2.zero; _movementVector = Vector2.zero;
transform.position = _originalPos; transform.position = _originalPos;
// charge state
_isCharging = false;
_timeSinceLastCharge = 0;
_opponentsHit.Clear(); _opponentsHit.Clear();
// detection state
IsEnemyDetected = false; IsEnemyDetected = false;
Enemy = null; Enemy = null;
// toggle detection
_detection.SetActive(true); _detection.SetActive(true);
_chargeDetection.SetActive(false); _chargeDetection.SetActive(false);
} }
} }
else else
{ {
_timeSinceLastCharge += Time.deltaTime;
if (IsEnemyDetected) if (IsEnemyDetected)
{ {
AttackEnemy(); AttackEnemy();
@ -76,7 +96,7 @@ public class Rider : Ally
void AttackEnemyRiding() void AttackEnemyRiding()
{ {
_rootScript.Attack(); _rootScript.AttackWithCustomDamage(_chargeAttackDamage);
_opponentsHit.Add(Enemy); _opponentsHit.Add(Enemy);
} }

View File

@ -24,6 +24,18 @@ 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() public void ShotProjectile()
{ {
Rigidbody2D _rigidbodyAlly; Rigidbody2D _rigidbodyAlly;