Commit 6f7548ef authored by 15김민규's avatar 15김민규

넉백 코루틴을 velocity 교정 방식을 통해 잘 구현했다(고 정신승리). 하지만 아직 다른걸 안고쳐서 미완성. 이제 enemy 코드 중...

넉백 코루틴을 velocity 교정 방식을 통해 잘 구현했다(고 정신승리). 하지만 아직 다른걸 안고쳐서 미완성. 이제 enemy 코드 중 movePosition 붙어있는 것을 싹 다 후려갈길 것임
parent 9a61c8e8
...@@ -32,7 +32,7 @@ AnimatorController: ...@@ -32,7 +32,7 @@ AnimatorController:
m_DefaultInt: 0 m_DefaultInt: 0
m_DefaultBool: 0 m_DefaultBool: 0
m_Controller: {fileID: 0} m_Controller: {fileID: 0}
- m_Name: knockbackDistance - m_Name: knockbackTime
m_Type: 1 m_Type: 1
m_DefaultFloat: 0 m_DefaultFloat: 0
m_DefaultInt: 0 m_DefaultInt: 0
...@@ -287,7 +287,7 @@ AnimatorState: ...@@ -287,7 +287,7 @@ AnimatorState:
m_SpeedParameter: m_SpeedParameter:
m_MirrorParameter: m_MirrorParameter:
m_CycleOffsetParameter: m_CycleOffsetParameter:
m_TimeParameter: m_TimeParameter: knockbackTime
--- !u!1102 &1102455672269219010 --- !u!1102 &1102455672269219010
AnimatorState: AnimatorState:
serializedVersion: 5 serializedVersion: 5
...@@ -314,7 +314,7 @@ AnimatorState: ...@@ -314,7 +314,7 @@ AnimatorState:
m_SpeedParameter: m_SpeedParameter:
m_MirrorParameter: m_MirrorParameter:
m_CycleOffsetParameter: m_CycleOffsetParameter:
m_TimeParameter: knockbackDistance m_TimeParameter: knockbackTime
--- !u!1102 &1102828359910447394 --- !u!1102 &1102828359910447394
AnimatorState: AnimatorState:
serializedVersion: 5 serializedVersion: 5
......
...@@ -158,7 +158,7 @@ Prefab: ...@@ -158,7 +158,7 @@ Prefab:
- target: {fileID: 224393982547383572, guid: 692aad2449e06054799ea4706578fb23, - target: {fileID: 224393982547383572, guid: 692aad2449e06054799ea4706578fb23,
type: 2} type: 2}
propertyPath: m_RootOrder propertyPath: m_RootOrder
value: 14 value: 13
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 224393982547383572, guid: 692aad2449e06054799ea4706578fb23, - target: {fileID: 224393982547383572, guid: 692aad2449e06054799ea4706578fb23,
type: 2} type: 2}
...@@ -1589,48 +1589,6 @@ MonoBehaviour: ...@@ -1589,48 +1589,6 @@ MonoBehaviour:
type: 2} type: 2}
m_PrefabInternal: {fileID: 1317359797} m_PrefabInternal: {fileID: 1317359797}
m_Script: {fileID: 11500000, guid: 674793b622d7c184882dfeb8784bbf92, type: 3} m_Script: {fileID: 11500000, guid: 674793b622d7c184882dfeb8784bbf92, type: 3}
--- !u!1001 &1909649316
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4639192263818050, guid: a164c147037e89448820f7387c724c42, type: 2}
propertyPath: m_LocalPosition.x
value: 6.01
objectReference: {fileID: 0}
- target: {fileID: 4639192263818050, guid: a164c147037e89448820f7387c724c42, type: 2}
propertyPath: m_LocalPosition.y
value: 2.009
objectReference: {fileID: 0}
- target: {fileID: 4639192263818050, guid: a164c147037e89448820f7387c724c42, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4639192263818050, guid: a164c147037e89448820f7387c724c42, type: 2}
propertyPath: m_LocalRotation.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4639192263818050, guid: a164c147037e89448820f7387c724c42, type: 2}
propertyPath: m_LocalRotation.y
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4639192263818050, guid: a164c147037e89448820f7387c724c42, type: 2}
propertyPath: m_LocalRotation.z
value: -0
objectReference: {fileID: 0}
- target: {fileID: 4639192263818050, guid: a164c147037e89448820f7387c724c42, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4639192263818050, guid: a164c147037e89448820f7387c724c42, type: 2}
propertyPath: m_RootOrder
value: 13
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: a164c147037e89448820f7387c724c42, type: 2}
m_IsPrefabAsset: 0
--- !u!1 &1931263424 --- !u!1 &1931263424
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
......
...@@ -11,9 +11,8 @@ public class AttackProperty : MonoBehaviour{ ...@@ -11,9 +11,8 @@ public class AttackProperty : MonoBehaviour{
private void OnTriggerEnter2D(Collider2D collision) private void OnTriggerEnter2D(Collider2D collision)
{ {
if (collision.CompareTag("Enemy") && !collision.transform.GetChild(0).GetComponent<Enemy>().untouchable) if (collision.CompareTag("Enemy") && !collision.transform.GetChild(0).GetComponent<Enemy>().Invisible)
{ {
Debug.Log(damage);
PlayerAttackInfo curAttack = new PlayerAttackInfo(damage, knockBackMultiplier, debuffNum, debuffType, debuffTime); PlayerAttackInfo curAttack = new PlayerAttackInfo(damage, knockBackMultiplier, debuffNum, debuffType, debuffTime);
Enemy enemyInfo = collision.transform.GetChild(0).GetComponent<Enemy>(); Enemy enemyInfo = collision.transform.GetChild(0).GetComponent<Enemy>();
collision.transform.GetChild(0).GetComponent<Enemy>().GetDamaged(curAttack); collision.transform.GetChild(0).GetComponent<Enemy>().GetDamaged(curAttack);
......
...@@ -24,7 +24,7 @@ public class EnemyMeleeIdle : StateMachineBehaviour { ...@@ -24,7 +24,7 @@ public class EnemyMeleeIdle : StateMachineBehaviour {
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
if (animator.GetComponent<Enemy>().playerDistance < noticeRange) if (animator.GetComponent<Enemy>().PlayerDistance < noticeRange)
{ {
animator.SetTrigger("TrackTrigger"); animator.SetTrigger("TrackTrigger");
return; return;
......
...@@ -26,7 +26,7 @@ public class EnemyMeleeTrack : StateMachineBehaviour { ...@@ -26,7 +26,7 @@ public class EnemyMeleeTrack : StateMachineBehaviour {
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
if (animator.GetComponent<Enemy>().playerDistance < attackRange) if (animator.GetComponent<Enemy>().PlayerDistance < attackRange)
{ {
animator.SetTrigger("AttackTrigger"); animator.SetTrigger("AttackTrigger");
return; return;
......
...@@ -35,10 +35,11 @@ public class Enemy : MonoBehaviour { ...@@ -35,10 +35,11 @@ public class Enemy : MonoBehaviour {
private EnemyManager enemyManager; private EnemyManager enemyManager;
// for animation // for animation
[HideInInspector]
public float playerDistance;
private Animator animator; private Animator animator;
public bool untouchable = false; public bool Invisible { get; private set; }
public bool Untouchable { get; private set; }
public float PlayerDistance { get; private set; }
private readonly float knockbackCritPoint = 0.25f;
// drop item // drop item
private int[] dropTable; private int[] dropTable;
...@@ -55,14 +56,15 @@ public class Enemy : MonoBehaviour { ...@@ -55,14 +56,15 @@ public class Enemy : MonoBehaviour {
private void Start() private void Start()
{ {
this.currHealth = maxHealth; currHealth = maxHealth;
Invisible = Untouchable = false;
dropTable = enemyManager.DropTableByID[monsterID]; dropTable = enemyManager.DropTableByID[monsterID];
Physics2D.IgnoreCollision(enemyManager.Player.gameObject.GetComponent<Collider2D>(), transform.parent.GetComponent<Collider2D>()); Physics2D.IgnoreCollision(enemyManager.Player.gameObject.GetComponent<Collider2D>(), transform.parent.GetComponent<Collider2D>());
} }
private void Update() private void Update()
{ {
playerDistance = Vector2.Distance(enemyManager.Player.transform.position, transform.parent.position); PlayerDistance = Vector2.Distance(enemyManager.Player.transform.position, transform.parent.position);
} }
// hit by player or debuff // hit by player or debuff
...@@ -70,13 +72,20 @@ public class Enemy : MonoBehaviour { ...@@ -70,13 +72,20 @@ public class Enemy : MonoBehaviour {
currHealth -= attack.damage; currHealth -= attack.damage;
if (currHealth <= 0) if (currHealth <= 0)
{ {
untouchable = true; Invisible = true;
animator.SetTrigger("DeadTrigger"); animator.SetTrigger("DeadTrigger");
return; return;
} }
animator.SetFloat("knockbackDistance", attack.damage / this.weight * attack.knockBackMultiplier); float knockbackDist = attack.damage * attack.knockBackMultiplier / weight;
if(attack.damage / this.weight >= 0.25f) float knockbackTime = (knockbackDist >= 0.5f) ? 0.5f : knockbackDist;
StartCoroutine(Knockback(knockbackDist, knockbackTime));
if (knockbackDist >= knockbackCritPoint)
{
animator.SetFloat("knockbackTime", knockbackTime);
animator.SetTrigger("DamagedTrigger"); animator.SetTrigger("DamagedTrigger");
}
} }
// Animation Event // Animation Event
...@@ -112,12 +121,10 @@ public class Enemy : MonoBehaviour { ...@@ -112,12 +121,10 @@ public class Enemy : MonoBehaviour {
} }
if (indexOfItem == 7) // Amethyst Potion if (indexOfItem == 7) // Amethyst Potion
{ {
Debug.Log("Amethyst Potion");
// insert! // insert!
} }
if (indexOfItem >= 8 && indexOfItem <= 11) // Item if (indexOfItem >= 8 && indexOfItem <= 11) // Item
{ {
Debug.Log("Item");
inventoryManager.ItemInstantiate((ItemQuality)(indexOfItem - 8), transform.parent.position, EnemyManager.dropObjStrength); inventoryManager.ItemInstantiate((ItemQuality)(indexOfItem - 8), transform.parent.position, EnemyManager.dropObjStrength);
} }
if (indexOfItem >= 12 && indexOfItem <= 15) // Addon if (indexOfItem >= 12 && indexOfItem <= 15) // Addon
...@@ -125,12 +132,30 @@ public class Enemy : MonoBehaviour { ...@@ -125,12 +132,30 @@ public class Enemy : MonoBehaviour {
inventoryManager.AddonInstantiate((ItemQuality)(indexOfItem - 12), transform.parent.position, EnemyManager.dropObjStrength); inventoryManager.AddonInstantiate((ItemQuality)(indexOfItem - 12), transform.parent.position, EnemyManager.dropObjStrength);
} }
this.currHealth = this.maxHealth; currHealth = maxHealth;
this.untouchable = false; Invisible = false;
return; return;
} }
// Coroutine // Coroutine
// Knockback
IEnumerator Knockback(float knockbackDist, float knockbackTime)
{
Untouchable = true;
bool isPlayerLeft = (enemyManager.Player.transform.position.x - transform.parent.position.x <= 0);
float knockbackVelocity = ((isPlayerLeft) ? 1 : -1) * knockbackDist / knockbackTime;
transform.parent.eulerAngles = (isPlayerLeft) ? new Vector2(0.0f, 0.0f) : new Vector2(0.0f, 180.0f);
Vector2 tempVelocity = transform.parent.GetComponent<Rigidbody2D>().velocity;
tempVelocity.x = knockbackVelocity;
transform.parent.GetComponent<Rigidbody2D>().velocity = tempVelocity;
yield return new WaitForSeconds(knockbackTime);
Untouchable = false;
}
// Debuff // Debuff
IEnumerator DebuffCase(EnemyDebuffed sCase) IEnumerator DebuffCase(EnemyDebuffed sCase)
{ {
...@@ -221,4 +246,4 @@ public class Enemy : MonoBehaviour { ...@@ -221,4 +246,4 @@ public class Enemy : MonoBehaviour {
* 13 - Addon(Ordinary) * 13 - Addon(Ordinary)
* 14 - Addon(Superior) * 14 - Addon(Superior)
* 15 - Addon(Masterpiece) * 15 - Addon(Masterpiece)
*/ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment