Commit c2da4e2a authored by Jordan B Mckenney's avatar Jordan B Mckenney

adding enemy and enemy fixes

parent 24be0262
......@@ -182,6 +182,7 @@ GameObject:
- component: {fileID: 50419609773635994}
- component: {fileID: 114527090549424528}
- component: {fileID: 58948533829961932}
- component: {fileID: 61428166331892880}
m_Layer: 9
m_Name: ChargeEnemy
m_TagString: Untagged
......@@ -445,8 +446,8 @@ Transform:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1013789244407342}
m_LocalRotation: {x: -0, y: -0, z: 0.39472097, w: 0.91880107}
m_LocalPosition: {x: 1.7937679, y: 0.12242079, z: 0}
m_LocalRotation: {x: 0, y: 0, z: -0.043170795, w: 0.9990677}
m_LocalPosition: {x: 1.5100732, y: 0.09456314, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4213753196664288}
......@@ -473,7 +474,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1688201806763842}
m_LocalRotation: {x: -0, y: -0, z: -0.86277705, w: -0.5055847}
m_LocalPosition: {x: 0.09, y: 0.017, z: 0}
m_LocalPosition: {x: 0.029524926, y: -0.024942394, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4572678037040202}
......@@ -485,7 +486,7 @@ Transform:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1955689948584328}
m_LocalRotation: {x: -0, y: -0, z: 0.73540807, w: 0.6776245}
m_LocalRotation: {x: 0, y: 0, z: 0.75197786, w: 0.6591884}
m_LocalPosition: {x: 0.38762912, y: -0.025493357, z: 1.940064}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
......@@ -513,7 +514,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1279584148291052}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 4.07, y: 4.735, z: 0}
m_LocalPosition: {x: 14.151994, y: 6.018202, z: 0}
m_LocalScale: {x: 0.3, y: 0.3, z: 1}
m_Children:
- {fileID: 4545735568619536}
......@@ -528,8 +529,8 @@ Transform:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1597335129924748}
m_LocalRotation: {x: -0, y: -0, z: 0.38814062, w: 0.92160016}
m_LocalPosition: {x: -0.33107442, y: 1.5897161, z: 0}
m_LocalRotation: {x: 0, y: 0, z: 0.82055146, w: 0.57157266}
m_LocalPosition: {x: -0.36776844, y: 1.5870224, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4303314183842092}
......@@ -542,7 +543,7 @@ Transform:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1877709968850946}
m_LocalRotation: {x: 0, y: 0, z: -0.9407658, w: 0.33905715}
m_LocalRotation: {x: 0, y: -0, z: 0.63136697, w: -0.7754842}
m_LocalPosition: {x: -0.21146503, y: 0.3612522, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
......@@ -589,7 +590,7 @@ Transform:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1195360342332106}
m_LocalRotation: {x: 0, y: 0, z: -0.19527066, w: -0.9807494}
m_LocalRotation: {x: 0, y: 0, z: 0.112042196, w: 0.9937035}
m_LocalPosition: {x: 0.4329423, y: 0.000000012572855, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
......@@ -635,8 +636,8 @@ Transform:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1272545819546654}
m_LocalRotation: {x: -0, y: -0, z: 0.4166121, w: 0.9090844}
m_LocalPosition: {x: 1.4142923, y: 0.3344028, z: 0}
m_LocalRotation: {x: 0, y: 0, z: -0.01923499, w: 0.999815}
m_LocalPosition: {x: 1.1300732, y: 0.30456316, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4168092519738170}
......@@ -662,8 +663,8 @@ Transform:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1488540775866384}
m_LocalRotation: {x: 0, y: 0, z: -0.50567704, w: 0.8627229}
m_LocalPosition: {x: 1.5458312, y: -0.58539164, z: 0}
m_LocalRotation: {x: 0, y: 0, z: -0.5776139, w: 0.8163101}
m_LocalPosition: {x: 1.5420393, y: -0.56111306, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4686167715700704}
......@@ -676,8 +677,8 @@ Transform:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1366847273805826}
m_LocalRotation: {x: -0, y: -0, z: -0.8627596, w: -0.50561446}
m_LocalPosition: {x: 0.044, y: 0.001, z: 0}
m_LocalRotation: {x: 0, y: 0, z: 0.8968013, w: 0.44243369}
m_LocalPosition: {x: -0.071962416, y: -0.017671913, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4572678037040202}
......@@ -689,8 +690,8 @@ Transform:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1393355784789758}
m_LocalRotation: {x: -0, y: -0, z: 0.39164245, w: 0.9201175}
m_LocalPosition: {x: 0.21334952, y: 1.5250542, z: 0}
m_LocalRotation: {x: 0, y: 0, z: 0.604252, w: 0.79679334}
m_LocalPosition: {x: 0.14087707, y: 1.5072985, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4806076897732236}
......@@ -729,7 +730,7 @@ Transform:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1479063918660956}
m_LocalRotation: {x: -0, y: -0, z: -0.728859, w: -0.68466383}
m_LocalRotation: {x: 0, y: 0, z: 0.79863554, w: 0.60181504}
m_LocalPosition: {x: -0.134, y: 0.066, z: 1.940064}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
......@@ -742,7 +743,7 @@ Transform:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1180648514802558}
m_LocalRotation: {x: -0, y: -0, z: 0.7328259, w: 0.6804162}
m_LocalRotation: {x: 0, y: 0, z: 0.7494644, w: 0.66204476}
m_LocalPosition: {x: 0.35315055, y: -0.020708218, z: 1.940064}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
......@@ -755,8 +756,8 @@ Transform:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1200204638840840}
m_LocalRotation: {x: -0, y: -0, z: -0.88961744, w: -0.45670664}
m_LocalPosition: {x: 0.07, y: 0.02, z: 1.940064}
m_LocalRotation: {x: 0, y: 0, z: 0.90328264, w: 0.429046}
m_LocalPosition: {x: 0.05821031, y: -0.053579375, z: 1.940064}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 4572678037040202}
......@@ -796,6 +797,20 @@ CircleCollider2D:
m_Offset: {x: 0, y: 0}
serializedVersion: 2
m_Radius: 1.7106764
--- !u!61 &61428166331892880
BoxCollider2D:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1279584148291052}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_UsedByEffector: 0
m_Offset: {x: 1.14, y: 0}
serializedVersion: 2
m_Size: {x: 4.5, y: 1.38}
--- !u!95 &95923084685412510
Animator:
serializedVersion: 3
......@@ -904,17 +919,18 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 43e4e60b0ca845f46b29944b857dc156, type: 3}
m_Name:
m_EditorClassIdentifier:
speed: 0
speed: 5
maxMoveDistance: 5
rightCollisionPos: {fileID: 4545735568619536}
hasEnteredView: 0
DetectionDistance: 5
ChargeSpeed: 5
Charging: 0
Charging: 1
lm:
serializedVersion: 2
m_Bits: 4294966783
FallOffLedge: 1
anim: {fileID: 95923084685412510}
--- !u!114 &114697006165824948
MonoBehaviour:
m_ObjectHideFlags: 1
......@@ -1052,7 +1068,7 @@ SpriteRenderer:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1688201806763842}
m_Enabled: 1
m_Enabled: 0
m_CastShadows: 0
m_ReceiveShadows: 0
m_MotionVectors: 1
......@@ -1122,7 +1138,7 @@ SpriteRenderer:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1479063918660956}
m_Enabled: 1
m_Enabled: 0
m_CastShadows: 0
m_ReceiveShadows: 0
m_MotionVectors: 1
......@@ -1157,7 +1173,7 @@ SpriteRenderer:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1706050813605098}
m_Enabled: 0
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_MotionVectors: 1
......@@ -1262,7 +1278,7 @@ SpriteRenderer:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1200204638840840}
m_Enabled: 1
m_Enabled: 0
m_CastShadows: 0
m_ReceiveShadows: 0
m_MotionVectors: 1
......
......@@ -85,7 +85,7 @@ Rigidbody2D:
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 10
m_Mass: 1000
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
......@@ -93,7 +93,7 @@ Rigidbody2D:
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
m_Constraints: 4
--- !u!58 &58281733955334486
CircleCollider2D:
m_ObjectHideFlags: 1
......@@ -136,7 +136,7 @@ MonoBehaviour:
hasEnteredView: 0
jumpHeight: 3.5
onGround: 1
isJumping: 1
isJumping: 0
jumpIntervalTime: 1.5
--- !u!212 &212093604417389100
SpriteRenderer:
......
This diff is collapsed.
......@@ -31,8 +31,8 @@ public class BaseEnemy : MonoBehaviour {
//check for collision in dir direction and start horizontal check in collisionPos
protected bool CheckCollision(Vector2 dir, Vector3 collisionPos)
{
RaycastHit2D hitSide = Physics2D.Raycast(collisionPos, dir, .1f);
RaycastHit2D hitDown = Physics2D.Raycast(collisionPos, -transform.up, .1f);
RaycastHit2D hitSide = Physics2D.Raycast(collisionPos, dir, .1f, 1);
RaycastHit2D hitDown = Physics2D.Raycast(collisionPos, -transform.up, .1f, 1);
if (hitDown.collider != null && hitSide.collider == null)
{
return true;
......@@ -41,8 +41,7 @@ public class BaseEnemy : MonoBehaviour {
}
protected bool CheckCollisionCharge(Vector2 dir, Vector3 collisionPos)
{
RaycastHit2D hitSide = Physics2D.Raycast(collisionPos, dir, .1f);
RaycastHit2D hitSide = Physics2D.Raycast(collisionPos, dir, .1f, 1);
if (hitSide.collider == null)
{
return true;
......
......@@ -4,11 +4,11 @@ using UnityEngine;
public class EnemyCharge : BaseEnemy
{
public float DetectionDistance;
public float ChargeSpeed;
public bool Charging = false;
public LayerMask lm;
public bool FallOffLedge = false;
public float DetectionDistance;
public float ChargeSpeed;
public bool Charging = false;
public LayerMask lm;
public bool FallOffLedge = false;
public Animator anim;
new void Start()
......@@ -17,62 +17,61 @@ public class EnemyCharge : BaseEnemy
anim = gameObject.GetComponentInChildren<Animator>();
}
void Update()
{
{
Vector2 fwd;
if (transform.localScale.x < 0 )
{
// Raycast to check if player is in front with layermask to prevent it from detecting itself
fwd = Vector2.left;
}
else
{
fwd = Vector2.right;
}
RaycastHit2D hit;
Debug.DrawRay (transform.position, fwd);
hit = Physics2D.Raycast (transform.position, fwd, DetectionDistance, lm);
if (transform.localScale.x < 0)
{
// Raycast to check if player is in front with layermask to prevent it from detecting itself
fwd = Vector2.left;
}
else
{
fwd = Vector2.right;
}
RaycastHit2D hit;
hit = Physics2D.Raycast(transform.position, fwd, DetectionDistance, lm);
if (hit)
{
if (hit.collider.gameObject.CompareTag("Player"))
{//If it sees an object with tag "Player", Charging will be true
Charging = true;
}
}
if (Charging)
{ //Will stop or keep going based on FallOffLedge bool
//anim.SetBool("isIdle", false);
if (!FallOffLedge)
{
if (!CheckCollision(fwd, rightCollisionPos.position))
{
Charging = false;
Vector2 facing = transform.localScale;
facing.x *= -1;
transform.localScale = facing;
return;
}
}
else
{
if (hit)
{
if (hit.collider.gameObject.CompareTag ("Player"))
{//If it sees an object with tag "Player", Charging will be true
Charging = true;
}
}
if (Charging)
{ //Will stop or keep going based on FallOffLedge bool
anim.SetBool("isIdle", false);
if (!FallOffLedge)
{
if (!CheckCollision (fwd, transform.localScale.x < 0 ? rightCollisionPos.position : rightCollisionPos.position))
{
//Charging = false;
Vector2 facing = transform.localScale;
facing.x *= -1;
transform.localScale = facing;
return;
}
}
else
{
if (!CheckCollisionCharge (fwd, transform.localScale.x < 0 ? rightCollisionPos.position : rightCollisionPos.position))
{
//Charging = false;
Vector2 facing = transform.localScale;
facing.x *= -1;
transform.localScale = facing;
return;
}
}
Move (fwd);
speed = ChargeSpeed;
}
if (!CheckCollisionCharge(fwd, rightCollisionPos.position))
{
//Charging = false;
//Vector2 facing = transform.localScale;
//facing.x *= -1;
//transform.localScale = facing;
return;
}
}
Move(fwd);
speed = ChargeSpeed;
}
else
{
anim.SetBool("isIdle", true);
//anim.SetBool("isIdle", true);
}
}
}
}
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