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
11 changed files with 92 additions and 1980 deletions
Showing only changes of commit cf1f88f43a - Show all commits

View File

@ -1,135 +0,0 @@
fileFormatVersion: 2
guid: 0f9488183cb57b242b27a65ea48f8dcb
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Server
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Android
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -10,7 +10,7 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a92d696df7037b44585aaac56ec9ed98, type: 3}
m_Name: Rider
m_Name: KnightOnHorse
m_EditorClassIdentifier:
_wood: 0
_rock: 0

View File

@ -10,7 +10,7 @@ MonoBehaviour:
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d1391306ffe53984bb2bc314f1d2919f, type: 3}
m_Name: Upgrade_Rider
m_Name: Upgrade_KnightOnHorse
m_EditorClassIdentifier:
_upgradeUnitCard: {fileID: 11400000, guid: 4855deb66869b934bb7a63c02d4442fe, type: 2}
_upgradePrefab: {fileID: 2230360378425099702, guid: a857e93871a186749879c021675f5a13, type: 3}

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: d57d97357919087419f8097e907c7a7e
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -2,7 +2,7 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rider : Ally
public class KnightOnHorse : Ally
{
[SerializeField]
private int _chargeAttackDamage;
@ -21,17 +21,23 @@ public class Rider : Ally
[SerializeField]
private GameObject _root;
// scripts
private Root _rootScript;
private Detection _detectionScript;
// attack variables
private int _originalAttackDamage;
// movement variables
private Vector3 _originalPos;
private Vector2 _movementVector = Vector2.zero;
// charge variables
private bool _isCharging;
private float _timeSinceLastCharge;
private List<Entity> _opponentsHit = new List<Entity>();
// fading variables
private float _fadeProgress;
private bool _isFading;
private int _fadeState;
@ -43,70 +49,24 @@ public class Rider : Ally
_rootScript = _root.GetComponent<Root>();
_detectionScript = _detection.GetComponent<Detection>();
// keep originals to go back to them eventually
_originalAttackDamage = _chargeAttackDamage;

Changer la valeur à "AttackDamage" d'Ally. Présentement, la valeur est la même pour une attaque de charge et une attaque normale.

Changer la valeur à "AttackDamage" d'Ally. Présentement, la valeur est la même pour une attaque de charge et une attaque normale.
_originalPos = transform.position;
// makes sure the entity charges on creation
_timeSinceLastCharge = _chargeCooldown + 1;
}
public override void Update()
{
// fade if charge done
if (_isFading)
{
if (_fadeProgress < _fadeDistance && _fadeState == 0)
{
_movementVector.x = Time.deltaTime * Speed;
transform.position += (Vector3)_movementVector;
_fadeProgress += _movementVector.x / _fadeDistance;
foreach (SpriteRenderer spriteRenderer in SpriteRenderers)
{
spriteRenderer.color = new Color(1.0f, 1.0f, 1.0f, 1.0f - _fadeProgress);
}
}
else if (_fadeProgress > _fadeDistance && _fadeState == 0)
{
transform.position = new Vector3(_originalPos.x - _fadeDistance, _originalPos.y, _originalPos.z);
_fadeState = 1;
}
else if (_fadeProgress > _fadeDistance && _fadeState == 1 && _fadeProgress < _fadeDistance * 2)
{
_movementVector.x = Time.deltaTime * Speed;
transform.position += (Vector3)_movementVector;
_fadeProgress += _movementVector.x / _fadeDistance;
foreach (SpriteRenderer spriteRenderer in SpriteRenderers)
{
spriteRenderer.color = new Color(1.0f, 1.0f, 1.0f, _fadeProgress - _fadeDistance);
}
}
else
{
// disable fading
_isFading = false;
_fadeProgress = 0;
_fadeState = 0;
foreach (SpriteRenderer spriteRenderer in SpriteRenderers)
{
spriteRenderer.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
}
// reset position
_movementVector.x = 0;
transform.position = _originalPos;
// toggle detection
_detection.SetActive(true);
_chargeDetection.SetActive(false);
// toggle animation
Animation.ToggleChargeAnim(false);
}
HandleFading();
return;
}
// check for charge cooldown
// check if charge is ready
if (_timeSinceLastCharge > _chargeCooldown && !_isCharging)
{
SweepAttack();
@ -117,14 +77,14 @@ public class Rider : Ally
if (_isCharging)
{
// sweep attack if an enemy slips behind the tip's hitbox
SweepAttack();
// toggle charge detection
_chargeDetection.SetActive(true);
// movement
_movementVector.x = Time.deltaTime * Speed;
transform.position += (Vector3)_movementVector;
HandleMovement();
// attack
if (IsEnemyDetected && !_opponentsHit.Contains(Enemy))
@ -143,9 +103,6 @@ public class Rider : Ally
// detection state
IsEnemyDetected = false;
Enemy = null;
// toggle detection
_detection.SetActive(false);
_chargeDetection.SetActive(false);
// start fading
@ -154,13 +111,23 @@ public class Rider : Ally
}
else
{
// charge cooldown
_timeSinceLastCharge += Time.deltaTime;
// regular attack
if (IsEnemyDetected)
{
AttackEnemy();
}
}
}
private void HandleMovement()
{
_movementVector.x = Time.deltaTime * Speed;
transform.position += (Vector3)_movementVector;
}
private void AttackEnemy()
{
//Attack Cooldown
@ -169,7 +136,6 @@ public class Rider : Ally
AttackDamage = _originalAttackDamage;
Animation.PlayAttackAnim();
AttackSpeedWait = 0f;
}
@ -179,14 +145,19 @@ public class Rider : Ally
private void AttackEnemyRiding()
{
AttackDamage = _chargeAttackDamage;
// call root attack cause no specific animation
_rootScript.Attack();
_opponentsHit.Add(Enemy);
}
// 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
/*
* Attacks all enemies already in the default detection box during charge.
* Charge uses a different detection (at the tip) due to Enemy being the first opponent to enter the hitbox.
* Therefore enemies would only get hit when the previous Enemy exits the hitbox, 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
* and during in case something goes wrong and a monster slips through the charge hitbox.
*/
private void SweepAttack()
{
foreach (Entity entity in _detectionScript.DetectedEntities)
@ -197,9 +168,59 @@ public class Rider : Ally
AttackEnemyRiding();
}
}
if (_detectionScript.DetectedEntities.Count > 0)
}
private void HandleFading()
{
if (_fadeState == 0 && _fadeProgress < _fadeDistance)
{
_detection.SetActive(false);
HandleMovement();
//fade out
_fadeProgress += _movementVector.x / _fadeDistance;
foreach (SpriteRenderer spriteRenderer in SpriteRenderers)
{
spriteRenderer.color = new Color(1.0f, 1.0f, 1.0f, 1.0f - _fadeProgress);
}
}
else if (_fadeState == 0 && _fadeProgress > _fadeDistance)
{
// teleport behind original position to fade in
transform.position = new Vector3(_originalPos.x - _fadeDistance, _originalPos.y, _originalPos.z);
_fadeState = 1;
}
else if (_fadeState == 1 && _fadeProgress < _fadeDistance * 2)
{
HandleMovement();
// fade in
_fadeProgress += _movementVector.x / _fadeDistance;
foreach (SpriteRenderer spriteRenderer in SpriteRenderers)
{
spriteRenderer.color = new Color(1.0f, 1.0f, 1.0f, _fadeProgress - _fadeDistance);
}
}
else
{
// disable fading
_isFading = false;
_fadeProgress = 0;
_fadeState = 0;
foreach (SpriteRenderer spriteRenderer in SpriteRenderers)
{
spriteRenderer.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
}
// reset position
_movementVector.x = 0;
transform.position = _originalPos;
// toggle detection
_detection.SetActive(true);
_chargeDetection.SetActive(false);
// toggle animation
Animation.ToggleChargeAnim(false);
}
}
}

View File

@ -27,9 +27,11 @@ public class Detection : MonoBehaviour
_hasStartBeenCalled = true;
}
// Checks if Start ran once already.
// onEnable runs by default before Start so not everything is initialized.
// And I don't want to reinitialize the collider everytime I re-enable a unit's detection.
/*
* Checks if Start ran once already.
* onEnable runs by default before Start so not everything is initialized
* and I don't want to reinitialize the collider everytime I re-enable a unit's detection.
*/
protected void OnEnable()
{
if (_hasStartBeenCalled)