// Detect collisions with other enemies, or player (while invuln), to prevent stacking void OnTriggerStay2D(Collider2D col) { if (!noCollisions) { return; } WeightedEnemyPhysics OtherWEP = col.gameObject.GetComponent <WeightedEnemyPhysics>(); PlayerHP PHP = col.gameObject.GetComponent <PlayerHP> (); if (OtherWEP != null || (PHP != null && PlayerHP.invuln)) { Vector2 OtherPos = col.transform.position; Vector2 diff = (OtherPos - (Vector2)transform.position).normalized; Vector2 projection = Vector2.Dot(diff, velocity) * diff; if ((diff + projection.normalized).magnitude > diff.magnitude) { velocity -= projection * (1f + bounceScale); } } if (col.GetComponent <turtle_shield>()) { print("found it"); Vector2 dir = transform.position - col.gameObject.transform.position; dir = dir.normalized * 2; StartCoroutine(knock_force(dir)); } }
// Initialize void Start() { WEP = GetComponent <WeightedEnemyPhysics> (); WEP.maxSpeed = maxSpeed; am = GetComponentInChildren <Animator>(); StartCoroutine(checkCharge()); }
// Called once per frame void Update() { Vector2 pos = transform.position; if (GM.Instance.player == null) { return; } Vector2 lookAtPos = GM.Instance.player.transform.position; // Decide what direction to look towards Vector2 direction = lookAtPos - pos; WEP.acceleration = direction.normalized; // Only enable shooting if the turret has a shot lined up with the player float currentAngle = transform.eulerAngles.z; currentAngle = WeightedEnemyPhysics.normalDegrees(currentAngle); float targetAngle = Mathf.Atan2(WEP.acceleration.y, WEP.acceleration.x) * Mathf.Rad2Deg; targetAngle = WeightedEnemyPhysics.normalDegrees(targetAngle); float diff = targetAngle - currentAngle; diff = WeightedEnemyPhysics.normalDegrees(diff); SAP.shootingEnabled = (Mathf.Abs(diff) <= Mathf.Abs(aimAngleLeeway)); }
// Initialization void Start() { WEP = GetComponent <WeightedEnemyPhysics> (); shootingEnabled = true; cool_down = true; Invoke("reload", 1 / _fire_rate); }
// Initialization void Awake() { WEP = GetComponent <WeightedEnemyPhysics> (); WEP.maxSpeed = maxSpeed; SwarmersWEP = new List <WeightedEnemyPhysics>(1 + innerCount + outerCount); SpawnSwarm(); }
// Initialize void Start() { WEP = GetComponent <WeightedEnemyPhysics> (); WEP.maxSpeed = maxSpeed; clockwise = false; circling = false; delay = diveTime; }
// Initialize void Start() { WEP = GetComponent <WeightedEnemyPhysics> (); WEP.maxSpeed = maxSpeed; circling = true; delay = minCircleTime; divesSoFar = 0; }
public void unstun() { Rigidbody2D rb = GetComponentInChildren <Rigidbody2D>(); rb.isKinematic = true; WeightedEnemyPhysics ws = GetComponentInChildren <WeightedEnemyPhysics>(); ws.enabled = true; }
// Initialization void Awake() { WEP = GetComponent <WeightedEnemyPhysics> (); WEP.maxSpeed = 0f; SAP = GetComponent <ShootsAtPlayer> (); asteroid = GetComponentInParent <Asteroid> (); asteroid.addTurret(this); initDegreeClamp(); }
// Initialize void Start() { WEP = GetComponent <WeightedEnemyPhysics> (); WEP.maxSpeed = maxSpeed; SR = GetComponent <SpriteRenderer> (); normalSprite = SR.sprite; triggered = false; normalState = true; }
// Initialize void Start() { WEP = GetComponent <WeightedEnemyPhysics> (); WEP.maxSpeed = circleSpeed; SR = GetComponentInChildren <SpriteRenderer> (); SR.sprite = AsleepSprite; SO = GetComponent <ScrollingObject> (); SO.enabled = true; chasing = false; angry = false; }
// Initialize the degree clamp in the WEP private void initDegreeClamp() { WEP.clampPerp = true; Vector2 normal = transform.position - asteroid.transform.position; float theta = Mathf.Rad2Deg * Mathf.Atan2(normal.x, normal.y); float realDoF = 360f - degreesOfFreedom; // Have to do this to fix something... float minDegree = (90f - realDoF / 2) + theta; float maxDegree = (90f + realDoF / 2) + theta; WEP.minDegree = WeightedEnemyPhysics.normalDegrees(minDegree); WEP.maxDegree = WeightedEnemyPhysics.normalDegrees(maxDegree); }
// Spawn a single swarmer enemy at the given location, attached to this swarm private void SpawnOneSwarmer(Vector3 position) { GameObject newSwarmer = Instantiate(SwarmerPrefab); newSwarmer.transform.position = position; SwarmerCount++; WeightedEnemyPhysics newWEP = newSwarmer.GetComponent <WeightedEnemyPhysics> (); newWEP.maxSpeed = maxSpeed; SwarmersWEP.Add(newWEP); //GM.Instance.Spawn (newSwarmer); }
// Initialize void Start() { WEP = GetComponent <WeightedEnemyPhysics> (); leaderWEP = objToFollow.GetComponent <WeightedEnemyPhysics> (); if (!objToFollow) { SetControllerScript(true); return; } else { SetControllerScript(false); maxSpeed = getLeaderSpeed(); } WEP.maxSpeed = maxSpeed; }
public WeightedEnemyPhysics getLeaderWEP() { FollowerEnemy nextInChain = objToFollow.GetComponent <FollowerEnemy> (); if (nextInChain && nextInChain.enabled) { return(nextInChain.getLeaderWEP()); } else { WeightedEnemyPhysics newLeadWEP = objToFollow.GetComponent <WeightedEnemyPhysics> (); if (newLeadWEP) { return(newLeadWEP); } else { Debug.LogError("No leader WeightedEnemyPhysics component found"); return(null); } } }
// Called when damage is taken public void gotHit(Vector3 knock_back, int dmg = 1, bool noDrop = false) { if (special()) { HP -= dmg; } if (HP <= 0) { die(noDrop); } else //hit animation { take_hit th; if (th = GetComponentInChildren <take_hit>()) { th.hit(); WeightedEnemyPhysics ws = GetComponentInChildren <WeightedEnemyPhysics>(); if (ws) { ws.KnockBack(knock_back); } } } }
// Initialize void Start() { WEP = GetComponent <WeightedEnemyPhysics> (); WEP.maxSpeed = maxSpeed; }