Commit de12185d authored by 15김민규's avatar 15김민규

벽을 짚고 있는지 검사할 수 있음

parent 6f7548ef
...@@ -87,7 +87,7 @@ Transform: ...@@ -87,7 +87,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1225288737757304} m_GameObject: {fileID: 1225288737757304}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.234, y: 0.621, z: 0} m_LocalPosition: {x: -0.142, y: 0.626, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 4140258981397796} - {fileID: 4140258981397796}
...@@ -115,7 +115,7 @@ Transform: ...@@ -115,7 +115,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1734061800721222} m_GameObject: {fileID: 1734061800721222}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0.133, y: 0.009, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children: []
m_Father: {fileID: 4015301101001556} m_Father: {fileID: 4015301101001556}
...@@ -128,7 +128,7 @@ Transform: ...@@ -128,7 +128,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000} m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1636491341446076} m_GameObject: {fileID: 1636491341446076}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 6.01, y: 2.009, z: 0} m_LocalPosition: {x: 0.862, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 4015301101001556} - {fileID: 4015301101001556}
...@@ -167,7 +167,7 @@ BoxCollider2D: ...@@ -167,7 +167,7 @@ BoxCollider2D:
m_IsTrigger: 1 m_IsTrigger: 1
m_UsedByEffector: 0 m_UsedByEffector: 0
m_UsedByComposite: 0 m_UsedByComposite: 0
m_Offset: {x: 0.2218492, y: -0.06722689} m_Offset: {x: 0, y: -0.079675555}
m_SpriteTilingProperty: m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0} border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0} pivot: {x: 0, y: 0}
...@@ -178,7 +178,7 @@ BoxCollider2D: ...@@ -178,7 +178,7 @@ BoxCollider2D:
adaptiveTiling: 0 adaptiveTiling: 0
m_AutoTiling: 0 m_AutoTiling: 0
serializedVersion: 2 serializedVersion: 2
m_Size: {x: 0.17983007, y: 1.1344538} m_Size: {x: 0.19960898, y: 1.1095564}
m_EdgeRadius: 0 m_EdgeRadius: 0
--- !u!61 &61254635014177320 --- !u!61 &61254635014177320
BoxCollider2D: BoxCollider2D:
...@@ -192,7 +192,7 @@ BoxCollider2D: ...@@ -192,7 +192,7 @@ BoxCollider2D:
m_IsTrigger: 0 m_IsTrigger: 0
m_UsedByEffector: 0 m_UsedByEffector: 0
m_UsedByComposite: 0 m_UsedByComposite: 0
m_Offset: {x: -0.001632452, y: 0.5538476} m_Offset: {x: 0, y: 0.5554246}
m_SpriteTilingProperty: m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0} border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0} pivot: {x: 0, y: 0}
...@@ -203,7 +203,7 @@ BoxCollider2D: ...@@ -203,7 +203,7 @@ BoxCollider2D:
adaptiveTiling: 0 adaptiveTiling: 0
m_AutoTiling: 0 m_AutoTiling: 0
serializedVersion: 2 serializedVersion: 2
m_Size: {x: 0.5742383, y: 1.126192} m_Size: {x: 0.7505637, y: 1.109323}
m_EdgeRadius: 0 m_EdgeRadius: 0
--- !u!61 &61362187134790794 --- !u!61 &61362187134790794
BoxCollider2D: BoxCollider2D:
...@@ -267,8 +267,6 @@ MonoBehaviour: ...@@ -267,8 +267,6 @@ MonoBehaviour:
attackRange: 1 attackRange: 1
patrolSpeed: 1.5 patrolSpeed: 1.5
trackSpeed: 2.5 trackSpeed: 2.5
playerDistance: 0
untouchable: 0
--- !u!114 &114173716467154830 --- !u!114 &114173716467154830
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 1 m_ObjectHideFlags: 1
......
...@@ -488,7 +488,7 @@ Prefab: ...@@ -488,7 +488,7 @@ Prefab:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 1560605499280558, guid: 7c6db9a9ca4150a438bd5114c58a37cf, type: 2} - target: {fileID: 1560605499280558, guid: 7c6db9a9ca4150a438bd5114c58a37cf, type: 2}
propertyPath: m_IsActive propertyPath: m_IsActive
value: 1 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 7c6db9a9ca4150a438bd5114c58a37cf, type: 2} m_SourcePrefab: {fileID: 100100000, guid: 7c6db9a9ca4150a438bd5114c58a37cf, type: 2}
...@@ -1893,3 +1893,45 @@ RectTransform: ...@@ -1893,3 +1893,45 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0} m_Pivot: {x: 0, y: 0}
--- !u!1001 &2118897079
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: 0.862
objectReference: {fileID: 0}
- target: {fileID: 4639192263818050, guid: a164c147037e89448820f7387c724c42, type: 2}
propertyPath: m_LocalPosition.y
value: 0
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: 14
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: a164c147037e89448820f7387c724c42, type: 2}
m_IsPrefabAsset: 0
...@@ -37,7 +37,7 @@ public class Enemy : MonoBehaviour { ...@@ -37,7 +37,7 @@ public class Enemy : MonoBehaviour {
// for animation // for animation
private Animator animator; private Animator animator;
public bool Invisible { get; private set; } public bool Invisible { get; private set; }
public bool Untouchable { get; private set; } public bool DuringKnockback { get; private set; }
public float PlayerDistance { get; private set; } public float PlayerDistance { get; private set; }
private readonly float knockbackCritPoint = 0.25f; private readonly float knockbackCritPoint = 0.25f;
...@@ -57,16 +57,62 @@ public class Enemy : MonoBehaviour { ...@@ -57,16 +57,62 @@ public class Enemy : MonoBehaviour {
private void Start() private void Start()
{ {
currHealth = maxHealth; currHealth = maxHealth;
Invisible = Untouchable = false; Invisible = DuringKnockback = 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 FixedUpdate()
{
bool wallTest = IsTouchingWall();
if (wallTest)
{
Debug.Log("Touching wall");
}
bool cliffTest = IsAdvancingToCliff();
if (cliffTest)
{
Debug.Log("Advancing to cliff");
}
}
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);
} }
// check whether enemy is advancing to cliff
public bool IsAdvancingToCliff()
{
Vector2 velocity = transform.parent.GetComponent<Rigidbody2D>().velocity;
Vector2 colliderSize = transform.parent.GetComponent<BoxCollider2D>().size;
if (velocity.x == 0) { return false; }
int enemyDir = (velocity.x > 0) ? 1 : -1;
Vector2 origin = (Vector2)transform.parent.position + enemyDir * new Vector2(colliderSize.x / 2.0f, 0);
Vector2 direction = Vector2.down;
float distance = colliderSize.y / 2.0f;
int layerMask = LayerMask.NameToLayer("platform");
RaycastHit2D hit = Physics2D.Raycast(origin, direction, distance, layerMask);
return (hit.collider == null);
}
public bool IsTouchingWall()
{
int enemyDir = (transform.parent.eulerAngles.y == 180.0f) ? 1 : -1;
Vector2 colliderSize = transform.parent.GetComponent<BoxCollider2D>().size;
Vector2 origin = (Vector2)transform.parent.position + enemyDir * new Vector2(colliderSize.x / 2.0f, 0);
Vector2 direction = Vector2.right * enemyDir;
float distance = 0.02f;
int layerMask = LayerMask.GetMask("Wall", "OuterWall");
RaycastHit2D hit = Physics2D.Raycast(origin, direction, distance, layerMask);
return (hit.collider != null);
}
// hit by player or debuff // hit by player or debuff
public void GetDamaged(PlayerAttackInfo attack) { public void GetDamaged(PlayerAttackInfo attack) {
currHealth -= attack.damage; currHealth -= attack.damage;
...@@ -79,6 +125,8 @@ public class Enemy : MonoBehaviour { ...@@ -79,6 +125,8 @@ public class Enemy : MonoBehaviour {
float knockbackDist = attack.damage * attack.knockBackMultiplier / weight; float knockbackDist = attack.damage * attack.knockBackMultiplier / weight;
float knockbackTime = (knockbackDist >= 0.5f) ? 0.5f : knockbackDist; float knockbackTime = (knockbackDist >= 0.5f) ? 0.5f : knockbackDist;
if (!DuringKnockback)
{
StartCoroutine(Knockback(knockbackDist, knockbackTime)); StartCoroutine(Knockback(knockbackDist, knockbackTime));
if (knockbackDist >= knockbackCritPoint) if (knockbackDist >= knockbackCritPoint)
...@@ -87,6 +135,7 @@ public class Enemy : MonoBehaviour { ...@@ -87,6 +135,7 @@ public class Enemy : MonoBehaviour {
animator.SetTrigger("DamagedTrigger"); animator.SetTrigger("DamagedTrigger");
} }
} }
}
// Animation Event // Animation Event
// Dead // Dead
...@@ -141,7 +190,7 @@ public class Enemy : MonoBehaviour { ...@@ -141,7 +190,7 @@ public class Enemy : MonoBehaviour {
// Knockback // Knockback
IEnumerator Knockback(float knockbackDist, float knockbackTime) IEnumerator Knockback(float knockbackDist, float knockbackTime)
{ {
Untouchable = true; DuringKnockback = true;
bool isPlayerLeft = (enemyManager.Player.transform.position.x - transform.parent.position.x <= 0); bool isPlayerLeft = (enemyManager.Player.transform.position.x - transform.parent.position.x <= 0);
float knockbackVelocity = ((isPlayerLeft) ? 1 : -1) * knockbackDist / knockbackTime; float knockbackVelocity = ((isPlayerLeft) ? 1 : -1) * knockbackDist / knockbackTime;
...@@ -153,7 +202,7 @@ public class Enemy : MonoBehaviour { ...@@ -153,7 +202,7 @@ public class Enemy : MonoBehaviour {
yield return new WaitForSeconds(knockbackTime); yield return new WaitForSeconds(knockbackTime);
Untouchable = false; DuringKnockback = false;
} }
// Debuff // Debuff
......
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