được sơ sơ
This commit is contained in:
4
.idea/.idea.HALLUCINATE/.idea/workspace.xml
generated
4
.idea/.idea.HALLUCINATE/.idea/workspace.xml
generated
@@ -6,8 +6,10 @@
|
|||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="f9183c68-daf0-43b8-be4c-fad79983f91b" name="Changes" comment="">
|
<list default="true" id="f9183c68-daf0-43b8-be4c-fad79983f91b" name="Changes" comment="">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/.idea.HALLUCINATE/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.HALLUCINATE/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/.idea.HALLUCINATE/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.HALLUCINATE/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Assets/Prefabs/NPC/xNPC.prefab" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Prefabs/NPC/xNPC.prefab" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Assets/Prefabs/Shooter/Player/vShooterMelee_Inventory.prefab" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Prefabs/Shooter/Player/vShooterMelee_Inventory.prefab" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Assets/Scripts/AI NPC/AnimatorAI.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/AI NPC/AnimatorAI.cs" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/Assets/Scripts/AI NPC/AnimatorAI.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/AI NPC/AnimatorAI.cs" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Assets/Scripts/AI NPC/EnemyAI.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/AI NPC/EnemyAI.cs" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/Assets/Scripts/AI NPC/KamikazeAI.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/AI NPC/KamikazeAI.cs" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
|||||||
@@ -511,10 +511,11 @@ MonoBehaviour:
|
|||||||
player: {fileID: 0}
|
player: {fileID: 0}
|
||||||
moveSpeed: 3
|
moveSpeed: 3
|
||||||
rotateSpeed: 50
|
rotateSpeed: 50
|
||||||
patrolWaypoints: []
|
|
||||||
currentWaypointIndex: 0
|
|
||||||
patrolWaitTime: 2
|
patrolWaitTime: 2
|
||||||
|
patrolSpeed: 2.5
|
||||||
|
patrolRadius: 12
|
||||||
playerHasArtifact: 0
|
playerHasArtifact: 0
|
||||||
|
isAggroedBySound: 0
|
||||||
laserPrefab: {fileID: 3965388737199864462, guid: fbec2b501d70daa4c9cb481ba53fc0b8, type: 3}
|
laserPrefab: {fileID: 3965388737199864462, guid: fbec2b501d70daa4c9cb481ba53fc0b8, type: 3}
|
||||||
firePoint: {fileID: 5863061020199015852}
|
firePoint: {fileID: 5863061020199015852}
|
||||||
minShootDelay: 1
|
minShootDelay: 1
|
||||||
@@ -522,6 +523,12 @@ MonoBehaviour:
|
|||||||
dodgeForce: 8
|
dodgeForce: 8
|
||||||
dodgeDuration: 0.5
|
dodgeDuration: 0.5
|
||||||
dodgeCooldown: 3
|
dodgeCooldown: 3
|
||||||
|
minStrafeDuration: 0.5
|
||||||
|
maxStrafeDuration: 2.2
|
||||||
|
maxSpreadAngle: 6
|
||||||
|
burstInterval: 0.12
|
||||||
|
approachWeight: 0.35
|
||||||
|
minCombatDistance: 5
|
||||||
npcName: Guard
|
npcName: Guard
|
||||||
persona: You are a grumpy guard protecting gold.
|
persona: You are a grumpy guard protecting gold.
|
||||||
talkRange: 5
|
talkRange: 5
|
||||||
@@ -609,20 +616,13 @@ MonoBehaviour:
|
|||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 7522161431095319480}
|
m_GameObject: {fileID: 7522161431095319480}
|
||||||
m_Enabled: 0
|
m_Enabled: 1
|
||||||
m_EditorHideFlags: 0
|
m_EditorHideFlags: 0
|
||||||
m_Script: {fileID: 11500000, guid: 35bba55c2a743d042ab1fff35e29db50, type: 3}
|
m_Script: {fileID: 11500000, guid: 35bba55c2a743d042ab1fff35e29db50, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier: Assembly-CSharp::AnimatorAI
|
m_EditorClassIdentifier: Assembly-CSharp::AnimatorAI
|
||||||
debugMode: 1
|
forceGrounded: 1
|
||||||
debugColor: {r: 1, g: 0, b: 0.21842146, a: 1}
|
movementBoost: 1.5
|
||||||
useSimulation: 0
|
|
||||||
autoCycleSpeed: 0
|
|
||||||
simVerticalVelocity: 0
|
|
||||||
simIsSprinting: 0
|
|
||||||
simIsAiming: 0
|
|
||||||
simMoveSetID: 0
|
|
||||||
sprintThreshold: 0.8
|
|
||||||
dampTime: 0.1
|
dampTime: 0.1
|
||||||
--- !u!136 &9027690817715396964
|
--- !u!136 &9027690817715396964
|
||||||
CapsuleCollider:
|
CapsuleCollider:
|
||||||
@@ -702,18 +702,18 @@ PrefabInstance:
|
|||||||
- target: {fileID: 9500000, guid: f32cd9f795c1282478d3bc3fbd8b2831, type: 3}
|
- target: {fileID: 9500000, guid: f32cd9f795c1282478d3bc3fbd8b2831, type: 3}
|
||||||
propertyPath: m_Avatar
|
propertyPath: m_Avatar
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 9000000, guid: 340f99b8334a14c4a8a01dce6e1e5348, type: 3}
|
objectReference: {fileID: 9000000, guid: f32cd9f795c1282478d3bc3fbd8b2831, type: 3}
|
||||||
- target: {fileID: 9500000, guid: f32cd9f795c1282478d3bc3fbd8b2831, type: 3}
|
- target: {fileID: 9500000, guid: f32cd9f795c1282478d3bc3fbd8b2831, type: 3}
|
||||||
propertyPath: m_Controller
|
propertyPath: m_Controller
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 9100000, guid: 87885946b43e2d1449e1d5aa2042f8a8, type: 2}
|
objectReference: {fileID: 9100000, guid: 87885946b43e2d1449e1d5aa2042f8a8, type: 2}
|
||||||
- target: {fileID: 9500000, guid: f32cd9f795c1282478d3bc3fbd8b2831, type: 3}
|
- target: {fileID: 9500000, guid: f32cd9f795c1282478d3bc3fbd8b2831, type: 3}
|
||||||
propertyPath: m_UpdateMode
|
propertyPath: m_UpdateMode
|
||||||
value: 1
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 9500000, guid: f32cd9f795c1282478d3bc3fbd8b2831, type: 3}
|
- target: {fileID: 9500000, guid: f32cd9f795c1282478d3bc3fbd8b2831, type: 3}
|
||||||
propertyPath: m_AnimatePhysics
|
propertyPath: m_AnimatePhysics
|
||||||
value: 1
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
m_RemovedComponents: []
|
m_RemovedComponents: []
|
||||||
m_RemovedGameObjects: []
|
m_RemovedGameObjects: []
|
||||||
|
|||||||
@@ -4197,6 +4197,11 @@ MonoBehaviour:
|
|||||||
_spawnParticle: 1
|
_spawnParticle: 1
|
||||||
_spawnStepMark: 1
|
_spawnStepMark: 1
|
||||||
_useTriggerEnter: 1
|
_useTriggerEnter: 1
|
||||||
|
emitAINoise: 1
|
||||||
|
aiNoiseRange: 10
|
||||||
|
npcLayer:
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Bits: 0
|
||||||
leftFootTrigger: {fileID: 11408204}
|
leftFootTrigger: {fileID: 11408204}
|
||||||
rightFootTrigger: {fileID: 11477308}
|
rightFootTrigger: {fileID: 11477308}
|
||||||
currentStep: {fileID: 0}
|
currentStep: {fileID: 0}
|
||||||
|
|||||||
@@ -3,97 +3,86 @@ using UnityEngine.AI;
|
|||||||
using Invector;
|
using Invector;
|
||||||
using Invector.vEventSystems;
|
using Invector.vEventSystems;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// AnimatorAI: Advanced Invector-style Animator synchronization for EnemyAI.
|
|
||||||
/// Resolves T-pose by ensuring all core Invector parameters are correctly synced.
|
|
||||||
/// </summary>
|
|
||||||
public class AnimatorAI : MonoBehaviour, vIAnimatorStateInfoController
|
public class AnimatorAI : MonoBehaviour, vIAnimatorStateInfoController
|
||||||
{
|
{
|
||||||
protected Animator animator;
|
protected Animator animator;
|
||||||
protected EnemyAI enemyAI;
|
|
||||||
protected NavMeshAgent agent;
|
protected NavMeshAgent agent;
|
||||||
protected Rigidbody rb;
|
|
||||||
protected vHealthController healthController;
|
protected vHealthController healthController;
|
||||||
|
protected EnemyAI enemyAI;
|
||||||
|
protected KamikazeAI kamikazeAI;
|
||||||
|
|
||||||
[Header("Movement Settings")]
|
[Header("Force Settings")]
|
||||||
public float sprintThreshold = 0.8f;
|
public bool forceGrounded = true;
|
||||||
public float dampTime = 0.1f;
|
public float movementBoost = 1.2f;
|
||||||
public float groundDistanceValue = 0.05f;
|
public float dampTime = 0.1f;
|
||||||
|
|
||||||
public vAnimatorStateInfos animatorStateInfos { get; protected set; }
|
public vAnimatorStateInfos animatorStateInfos { get; protected set; }
|
||||||
|
|
||||||
#region Animator Parameters (Invector Style)
|
#region Animator Parameters
|
||||||
protected vAnimatorParameter isDead;
|
protected vAnimatorParameter isDead, isGrounded, isStrafing, isSprinting, isAiming;
|
||||||
protected vAnimatorParameter isGrounded;
|
protected vAnimatorParameter verticalVelocity, horizontalVelocity, inputMagnitude;
|
||||||
protected vAnimatorParameter isStrafing;
|
protected vAnimatorParameter groundDistance, moveSet_ID, attackID, triggerReaction, resetState;
|
||||||
protected vAnimatorParameter isSprinting;
|
|
||||||
protected vAnimatorParameter isAiming;
|
|
||||||
protected vAnimatorParameter verticalVelocity;
|
|
||||||
protected vAnimatorParameter horizontalVelocity;
|
|
||||||
protected vAnimatorParameter groundDistance;
|
|
||||||
protected vAnimatorParameter moveSet_ID;
|
|
||||||
protected vAnimatorParameter attackID;
|
|
||||||
protected vAnimatorParameter hitDirection;
|
|
||||||
protected vAnimatorParameter reactionID;
|
|
||||||
protected vAnimatorParameter triggerReaction;
|
|
||||||
protected vAnimatorParameter resetState;
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
protected Vector3 lastPosition;
|
protected Vector3 lastPosition;
|
||||||
protected float currentV;
|
protected float currentV, currentH, currentMagnitude, calculatedSpeed;
|
||||||
protected float currentH;
|
|
||||||
|
|
||||||
protected virtual void Awake()
|
protected virtual void Awake()
|
||||||
{
|
{
|
||||||
animator = GetComponentInChildren<Animator>();
|
animator = GetComponentInChildren<Animator>();
|
||||||
enemyAI = GetComponent<EnemyAI>();
|
if (animator == null) animator = GetComponentInParent<Animator>();
|
||||||
|
|
||||||
agent = GetComponent<NavMeshAgent>();
|
agent = GetComponent<NavMeshAgent>();
|
||||||
rb = GetComponent<Rigidbody>();
|
if (agent == null) agent = GetComponentInParent<NavMeshAgent>();
|
||||||
healthController = GetComponent<vHealthController>();
|
|
||||||
|
healthController = GetComponentInChildren<vHealthController>();
|
||||||
|
enemyAI = GetComponent<EnemyAI>();
|
||||||
|
kamikazeAI = GetComponent<KamikazeAI>();
|
||||||
|
|
||||||
if (animator)
|
if (animator)
|
||||||
{
|
{
|
||||||
|
animator.applyRootMotion = false;
|
||||||
|
animator.updateMode = AnimatorUpdateMode.Normal;
|
||||||
|
|
||||||
|
// Reset all layers initially to prevent T-Pose
|
||||||
|
for (int i = 1; i < animator.layerCount; i++) animator.SetLayerWeight(i, 0f);
|
||||||
|
|
||||||
animatorStateInfos = new vAnimatorStateInfos(animator);
|
animatorStateInfos = new vAnimatorStateInfos(animator);
|
||||||
InitializeParameters();
|
InitializeParameters();
|
||||||
|
Debug.Log($"<color=green>[AnimSystem]</color> Đã kích hoạt trên {gameObject.name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
lastPosition = transform.position;
|
lastPosition = transform.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnEnable()
|
protected virtual void OnEnable() { this.Register(); }
|
||||||
{
|
protected virtual void OnDisable() { this.UnRegister(); }
|
||||||
this.Register();
|
|
||||||
if (healthController) healthController.onReceiveDamage.AddListener(OnReceiveDamage);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnDisable()
|
|
||||||
{
|
|
||||||
this.UnRegister();
|
|
||||||
if (healthController) healthController.onReceiveDamage.RemoveListener(OnReceiveDamage);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void InitializeParameters()
|
protected virtual void InitializeParameters()
|
||||||
{
|
{
|
||||||
isDead = new vAnimatorParameter(animator, "isDead");
|
isDead = ValidateAndInit("isDead");
|
||||||
isGrounded = new vAnimatorParameter(animator, "IsGrounded");
|
isGrounded = ValidateAndInit("isGrounded");
|
||||||
isStrafing = new vAnimatorParameter(animator, "IsStrafing");
|
if (!isGrounded.isValid) isGrounded = ValidateAndInit("IsGrounded");
|
||||||
isSprinting = new vAnimatorParameter(animator, "IsSprinting");
|
isStrafing = ValidateAndInit("IsStrafing");
|
||||||
isAiming = new vAnimatorParameter(animator, "IsAiming");
|
isSprinting = ValidateAndInit("IsSprinting");
|
||||||
verticalVelocity = new vAnimatorParameter(animator, "VerticalVelocity");
|
isAiming = ValidateAndInit("IsAiming");
|
||||||
horizontalVelocity = new vAnimatorParameter(animator, "HorizontalVelocity");
|
verticalVelocity = ValidateAndInit("InputVertical");
|
||||||
groundDistance = new vAnimatorParameter(animator, "GroundDistance");
|
horizontalVelocity = ValidateAndInit("InputHorizontal");
|
||||||
moveSet_ID = new vAnimatorParameter(animator, "MoveSet_ID");
|
inputMagnitude = ValidateAndInit("InputMagnitude");
|
||||||
attackID = new vAnimatorParameter(animator, "AttackID");
|
groundDistance = ValidateAndInit("GroundDistance");
|
||||||
hitDirection = new vAnimatorParameter(animator, "HitDirection");
|
moveSet_ID = ValidateAndInit("MoveSet_ID");
|
||||||
reactionID = new vAnimatorParameter(animator, "ReactionID");
|
attackID = ValidateAndInit("AttackID");
|
||||||
triggerReaction = new vAnimatorParameter(animator, "TriggerReaction");
|
triggerReaction = ValidateAndInit("TriggerReaction");
|
||||||
resetState = new vAnimatorParameter(animator, "ResetState");
|
resetState = ValidateAndInit("ResetState");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private vAnimatorParameter ValidateAndInit(string pName) => new vAnimatorParameter(animator, pName);
|
||||||
|
|
||||||
protected virtual void Update()
|
protected virtual void Update()
|
||||||
{
|
{
|
||||||
if (animator == null || enemyAI == null || agent == null) return;
|
if (animator == null || agent == null) return;
|
||||||
|
|
||||||
UpdateMovementParameters();
|
UpdateMovementParameters();
|
||||||
UpdateCombatParameters();
|
UpdateCombatParameters();
|
||||||
@@ -101,106 +90,74 @@ public class AnimatorAI : MonoBehaviour, vIAnimatorStateInfoController
|
|||||||
|
|
||||||
protected virtual void UpdateMovementParameters()
|
protected virtual void UpdateMovementParameters()
|
||||||
{
|
{
|
||||||
// 1. Grounded & GroundDistance (Critical for T-pose prevention)
|
SetBool(isGrounded, forceGrounded);
|
||||||
bool grounded = agent.isOnNavMesh || agent.enabled;
|
SetFloat(groundDistance, 0f);
|
||||||
SetBool(isGrounded, grounded);
|
|
||||||
SetFloat(groundDistance, grounded ? 0f : groundDistanceValue);
|
|
||||||
|
|
||||||
// 2. Responsive Velocity Calculation
|
Vector3 delta = transform.position - lastPosition;
|
||||||
// Use a mix of agent velocity and position delta for better responsiveness
|
calculatedSpeed = delta.magnitude / Time.deltaTime;
|
||||||
Vector3 worldVelocity = (transform.position - lastPosition) / Time.deltaTime;
|
|
||||||
lastPosition = transform.position;
|
lastPosition = transform.position;
|
||||||
|
|
||||||
if (worldVelocity.magnitude < 0.01f) worldVelocity = Vector3.zero;
|
Vector3 localVel = transform.InverseTransformDirection(delta / Time.deltaTime);
|
||||||
|
|
||||||
Vector3 localVelocity = transform.InverseTransformDirection(worldVelocity);
|
|
||||||
|
|
||||||
float targetV = localVelocity.z / enemyAI.moveSpeed;
|
float maxS = (enemyAI) ? enemyAI.moveSpeed : (kamikazeAI ? agent.speed : 3f);
|
||||||
float targetH = localVelocity.x / enemyAI.moveSpeed;
|
if (maxS <= 0) maxS = 3f;
|
||||||
|
|
||||||
|
float targetV = (localVel.z / maxS) * movementBoost;
|
||||||
|
float targetH = (localVel.x / maxS) * movementBoost;
|
||||||
|
|
||||||
// Smooth velocity values
|
|
||||||
currentV = Mathf.Lerp(currentV, targetV, 10f * Time.deltaTime);
|
currentV = Mathf.Lerp(currentV, targetV, 10f * Time.deltaTime);
|
||||||
currentH = Mathf.Lerp(currentH, targetH, 10f * Time.deltaTime);
|
currentH = Mathf.Lerp(currentH, targetH, 10f * Time.deltaTime);
|
||||||
|
currentMagnitude = new Vector2(currentH, currentV).magnitude;
|
||||||
|
|
||||||
|
// ÉP GIÁ TRỊ VÀO ANIMATOR
|
||||||
SetFloat(verticalVelocity, currentV);
|
SetFloat(verticalVelocity, currentV);
|
||||||
SetFloat(horizontalVelocity, currentH);
|
SetFloat(horizontalVelocity, currentH);
|
||||||
|
SetFloat(inputMagnitude, currentMagnitude);
|
||||||
// 3. Sprinting
|
|
||||||
bool sprinting = worldVelocity.magnitude > (enemyAI.moveSpeed * sprintThreshold);
|
|
||||||
SetBool(isSprinting, sprinting);
|
|
||||||
|
|
||||||
// 4. Strafing
|
|
||||||
SetBool(isStrafing, enemyAI.playerHasArtifact);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void UpdateCombatParameters()
|
protected virtual void UpdateCombatParameters()
|
||||||
{
|
{
|
||||||
SetBool(isAiming, enemyAI.playerHasArtifact);
|
// 1. Kiểm tra trạng thái AI
|
||||||
SetInt(moveSet_ID, enemyAI.playerHasArtifact ? 1 : 0);
|
bool isShooting = (enemyAI && enemyAI.IsShootingBurst);
|
||||||
|
bool hasArtifact = (enemyAI && enemyAI.playerHasArtifact);
|
||||||
|
|
||||||
// Shooting burst
|
// 2. Cập nhật MoveSet và Aiming
|
||||||
if (enemyAI.IsShootingBurst)
|
SetInt(moveSet_ID, hasArtifact ? 1 : 0);
|
||||||
SetInt(attackID, 1);
|
SetBool(isAiming, hasArtifact);
|
||||||
|
SetBool(isStrafing, hasArtifact);
|
||||||
|
|
||||||
|
// 3. Xử lý BẮN SÚNG (Layer 6 trong Animator của bạn)
|
||||||
|
if (isShooting)
|
||||||
|
{
|
||||||
|
// Bật Layer bắn súng lên 1 (Smooth)
|
||||||
|
animator.SetLayerWeight(6, Mathf.Lerp(animator.GetLayerWeight(6), 1f, 15f * Time.deltaTime));
|
||||||
|
SetInt(attackID, 1); // Kích hoạt animation bắn trong Blend Tree của Layer 6
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
// Tắt Layer bắn súng về 0
|
||||||
|
animator.SetLayerWeight(6, Mathf.Lerp(animator.GetLayerWeight(6), 0f, 10f * Time.deltaTime));
|
||||||
SetInt(attackID, 0);
|
SetInt(attackID, 0);
|
||||||
|
|
||||||
// Dodge logic
|
|
||||||
if (enemyAI.IsDodging)
|
|
||||||
{
|
|
||||||
// In Invector, dodges are often handled via triggers or specific IDs
|
|
||||||
SetAnimatorTrigger(triggerReaction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Death state
|
if (enemyAI && enemyAI.IsDodging) SetAnimatorTrigger(triggerReaction);
|
||||||
if (healthController) SetBool(isDead, healthController.isDead);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnReceiveDamage(vDamage damage)
|
|
||||||
{
|
|
||||||
if (animator == null || !animator.enabled) return;
|
|
||||||
|
|
||||||
// Sync damage parameters for hit reactions
|
|
||||||
if (hitDirection.isValid && damage.sender)
|
|
||||||
{
|
|
||||||
float angle = transform.HitAngle(damage.sender.position);
|
|
||||||
animator.SetInteger(hitDirection, (int)angle);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reactionID.isValid) animator.SetInteger(reactionID, damage.reaction_id);
|
|
||||||
|
|
||||||
SetAnimatorTrigger(triggerReaction);
|
|
||||||
SetAnimatorTrigger(resetState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Helpers
|
#region Helpers
|
||||||
protected void SetBool(vAnimatorParameter param, bool value)
|
protected void SetBool(vAnimatorParameter p, bool v) { if (p.isValid) animator.SetBool(p, v); }
|
||||||
{
|
protected void SetFloat(vAnimatorParameter p, float v) { if (p.isValid) animator.SetFloat(p, v, dampTime, Time.deltaTime); }
|
||||||
if (param.isValid && animator.GetBool(param) != value)
|
protected void SetInt(vAnimatorParameter p, int v) { if (p.isValid) animator.SetInteger(p, v); }
|
||||||
animator.SetBool(param, value);
|
|
||||||
|
public void SetAnimatorTrigger(vAnimatorParameter trigger)
|
||||||
|
{
|
||||||
|
if (trigger.isValid) StartCoroutine(SetTriggerRoutine(trigger));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void SetFloat(vAnimatorParameter param, float value)
|
private IEnumerator SetTriggerRoutine(int targetHash)
|
||||||
{
|
{
|
||||||
if (param.isValid)
|
animator.SetTrigger(targetHash);
|
||||||
animator.SetFloat(param, value, dampTime, Time.deltaTime);
|
yield return new WaitForSeconds(0.1f);
|
||||||
}
|
animator.ResetTrigger(targetHash);
|
||||||
|
|
||||||
protected void SetInt(vAnimatorParameter param, int value)
|
|
||||||
{
|
|
||||||
if (param.isValid && animator.GetInteger(param) != value)
|
|
||||||
animator.SetInteger(param, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetAnimatorTrigger(vAnimatorParameter trigger)
|
|
||||||
{
|
|
||||||
if (trigger.isValid) StartCoroutine(SetTriggerRoutine(trigger));
|
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerator SetTriggerRoutine(int targetHash)
|
|
||||||
{
|
|
||||||
animator.SetTrigger(targetHash);
|
|
||||||
yield return new WaitForSeconds(0.1f);
|
|
||||||
animator.ResetTrigger(targetHash);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class KamikazeAI : MonoBehaviour
|
|||||||
// HÀM TUẦN TRA NGẪU NHIÊN MỚI
|
// HÀM TUẦN TRA NGẪU NHIÊN MỚI
|
||||||
private NodeState ActionRandomPatrol()
|
private NodeState ActionRandomPatrol()
|
||||||
{
|
{
|
||||||
Debug.Log("Wandering randomly...");
|
// Debug.Log("Wandering randomly...");
|
||||||
agent.isStopped = false;
|
agent.isStopped = false;
|
||||||
agent.speed = patrolSpeed;
|
agent.speed = patrolSpeed;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user