Commit 70aeb693 authored by 15김민규's avatar 15김민규

넉백 구현. 너무 길다 싶으면 애니메이션 길이를 조정할 것

parent e4de4bcb
......@@ -13,25 +13,31 @@ AnimatorController:
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: AttackTrigger
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: DamagedTrigger
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: DeadTrigger
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: knockbackDistance
m_Type: 1
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
......
......@@ -6,8 +6,11 @@ public class Damaged : StateMachineBehaviour {
RuntimeAnimatorController ac;
float knockbackTime;
float knockbackSpeed;
float knockbackDir; // 1: right \ -1: left
Vector3 leftsideAngle = new Vector3(0, 0, 0);
Vector3 rightsideAngle = new Vector3(0, 180, 0);
Transform pivotTransform;
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
......@@ -19,14 +22,19 @@ public class Damaged : StateMachineBehaviour {
knockbackTime = clip.length;
}
}
knockbackSpeed = animator.GetFloat("knockbackDistance") / knockbackTime;
Transform playerTransform = EnemyManager.Instance.player.transform;
Transform pivotTransform = animator.transform.parent;
pivotTransform = animator.transform.parent;
pivotTransform.eulerAngles = (playerTransform.position.x - pivotTransform.position.x < 0) ? leftsideAngle : rightsideAngle;
knockbackDir = (playerTransform.position.x - pivotTransform.position.x < 0) ? 1 : -1;
}
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
Vector2 currPosition = pivotTransform.position;
Vector2 movingDistance = new Vector2(knockbackSpeed * Time.deltaTime, 0) * knockbackDir;
pivotTransform.gameObject.GetComponent<Rigidbody2D>().MovePosition(currPosition + movingDistance);
}
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state
......
......@@ -71,7 +71,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1225288737757304}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.15799999, y: 0.40100002, z: 0}
m_LocalPosition: {x: -0.234, y: 0.621, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4140258981397796}
......@@ -98,7 +98,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1636491341446076}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 6.876, y: 1.034, z: -0.1645136}
m_LocalPosition: {x: 6.01, y: 2.009, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4015301101001556}
......@@ -133,11 +133,11 @@ BoxCollider2D:
m_GameObject: {fileID: 1636491341446076}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_Material: {fileID: 6200000, guid: 90e689a435f304c469db49daef28ed89, type: 2}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0.08, y: 0.325}
m_Offset: {x: -0.020877361, y: 0.5497493}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
......@@ -148,7 +148,7 @@ BoxCollider2D:
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 0.55, y: 1.1}
m_Size: {x: 0.5978651, y: 1.1179954}
m_EdgeRadius: 0
--- !u!61 &61362187134790794
BoxCollider2D:
......@@ -206,7 +206,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
monsterID: 101
maxHealth: 5
weight: 3
weight: 1
patrolRange: 2
noticeRange: 2
attackRange: 1
......
......@@ -1090,7 +1090,7 @@ Prefab:
- target: {fileID: 114685218848006942, guid: e6794ab8e2e4c6340a23b382e9497cbb,
type: 2}
propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName
value: UpgradeStage
value: SummonEnemy
objectReference: {fileID: 0}
- target: {fileID: 224008356030171754, guid: e6794ab8e2e4c6340a23b382e9497cbb,
type: 2}
......@@ -1117,6 +1117,11 @@ Prefab:
propertyPath: m_RootOrder
value: 9
objectReference: {fileID: 0}
- target: {fileID: 224667404527337120, guid: e6794ab8e2e4c6340a23b382e9497cbb,
type: 2}
propertyPath: m_RootOrder
value: 10
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: e6794ab8e2e4c6340a23b382e9497cbb, type: 2}
m_IsPrefabAsset: 0
......@@ -1240,15 +1245,15 @@ Prefab:
m_Modifications:
- target: {fileID: 4639192263818050, guid: a164c147037e89448820f7387c724c42, type: 2}
propertyPath: m_LocalPosition.x
value: 6.876
value: 6.01
objectReference: {fileID: 0}
- target: {fileID: 4639192263818050, guid: a164c147037e89448820f7387c724c42, type: 2}
propertyPath: m_LocalPosition.y
value: 1.034
value: 2.009
objectReference: {fileID: 0}
- target: {fileID: 4639192263818050, guid: a164c147037e89448820f7387c724c42, type: 2}
propertyPath: m_LocalPosition.z
value: -0.1645136
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4639192263818050, guid: a164c147037e89448820f7387c724c42, type: 2}
propertyPath: m_LocalRotation.x
......
......@@ -40,6 +40,7 @@ public class Enemy : MonoBehaviour {
// for animation
[HideInInspector]
public float playerDistance;
private Animator animator;
// drop item
......@@ -49,12 +50,12 @@ public class Enemy : MonoBehaviour {
private void Awake()
{
enemyManager = EnemyManager.Instance;
animator = GetComponent<Animator>();
}
private void Start()
{
this.currHealth = maxHealth;
playerDistance = Vector2.Distance(enemyManager.player.transform.position, transform.parent.position);
}
private void Update()
......@@ -69,7 +70,8 @@ public class Enemy : MonoBehaviour {
gameObject.SetActive(false);
return;
}
gameObject.GetComponent<Animator>().SetTrigger("DamagedTrigger");
animator.SetFloat("knockbackDistance", damage / this.weight);
animator.SetTrigger("DamagedTrigger");
}
IEnumerator DebuffCase(EnemyDebuffed sCase)
......
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