void OnCollisionEnter2D(Collision2D col) { if (col.rigidbody || col.gameObject.CompareTag("DPlatform")){ if (first) { first = false; second = true; } else if (second){ second = false; StartCoroutine (SelfDestruct ()); } if (!hit){ force = Mathf.Abs (Vector2.Dot(col.contacts[0].normal,col.relativeVelocity) * rigidbody2D.mass); if (force>forceThresh) { if (col.gameObject.GetComponent<GetDamage>() && !hit){ getDamage = col.gameObject.GetComponent<GetDamage>(); hit = true; } if (hit){ StartCoroutine(getDamage.SendDamage(smallBulletDamage,blockType)); } } } } }
void OnCollisionEnter2D(Collision2D col) { if (col.rigidbody || col.gameObject.CompareTag("DPlatform")) { if (first) { first = false; second = true; } else if (second) { second = false; StartCoroutine(SelfDestruct()); } if (!hit) { force = Mathf.Abs(Vector2.Dot(col.contacts[0].normal, col.relativeVelocity) * rigidbody2D.mass); if (force > forceThresh) { if (col.gameObject.GetComponent <GetDamage>() && !hit) { getDamage = col.gameObject.GetComponent <GetDamage>(); hit = true; } if (hit) { StartCoroutine(getDamage.SendDamage(smallBulletDamage, blockType)); } } } } }
void OnCollisionEnter2D(Collision2D col) { if (rigidbody2D) { i = 0; force = Mathf.Abs(Vector2.Dot(col.contacts[0].normal, col.relativeVelocity) * rigidbody2D.mass); doDamage = false; if (force > 5f && Vector2.Distance(Vector2.zero, rigidbody2D.velocity) > 2f) { if (nowProjectile && col.gameObject.GetComponent <GetDamage>()) { doDamage = true; if (blockType == 7 || blockType == 8) //telekinetic blocks { if (col.gameObject.GetComponent <Player>()) { //only hurt on mismatch (so the owner of the block doesn't hurt himself or his other Telekineticblocks) if ((col.gameObject.GetComponent <Player>().char1&& wepDSID == 1) || (col.gameObject.GetComponent <Player>().char2&& wepDSID == 2)) { doDamage = false; } } else if (col.gameObject.GetComponent <TelekineticBlock>()) { if ((col.gameObject.GetComponent <TelekineticBlock>().wepDSID == wepDSID)) { doDamage = false; } } else if (col.gameObject.GetComponent <SuperTelekineticBlock>()) { if ((col.gameObject.GetComponent <SuperTelekineticBlock>().wepDSID == wepDSID)) { doDamage = false; } } } } } if (doDamage) { GetDamage getDamage = col.gameObject.GetComponent <GetDamage>(); damageFactor = force / maxForce; if (damageFactor > 1) { damageFactor = 1; } hurtNoise.volume = damageFactor; hurtNoise.Play(); damage2Deal = Mathf.RoundToInt(damageFactor * blockDamage); StartCoroutine(getDamage.SendDamage(damage2Deal, 1)); } } }
void OnCollisionEnter2D(Collision2D collision) { hitObject = collision.collider.gameObject; if (hitObject.GetComponent<GetDamage>()){ getDamage = hitObject.GetComponent<GetDamage>(); getDamage.StartCoroutine(getDamage.SendDamage(missleDamage,blockType)); Destroy (this.gameObject); } }
void OnCollisionEnter2D(Collision2D collision) { hitObject = collision.collider.gameObject; if (hitObject.GetComponent <GetDamage>()) { getDamage = hitObject.GetComponent <GetDamage>(); getDamage.StartCoroutine(getDamage.SendDamage(missleDamage, blockType)); Destroy(this.gameObject); } }
void OnTriggerEnter2D(Collider2D col) { if (smacking || smashing) { if (col.gameObject.GetComponent <GetDamage>() && !col.gameObject.CompareTag("Player")) { getDamageScript = col.gameObject.GetComponent <GetDamage>(); if (smacking) { damage = smackDamage; } else { damage = smackDamage; } StartCoroutine(getDamageScript.SendDamage(damage, weaponType)); } } }
void OnCollisionEnter2D(Collision2D col) { damageable = false; if (col.rigidbody) { if (col.gameObject.GetComponent <GetDamage>()) { getDamage = col.gameObject.GetComponent <GetDamage>(); damageable = true; } colliderSpeed = col.rigidbody.velocity.magnitude; } else if (col.transform.parent) //so if this is a child gameobject with a collider, its rigidbody is on the parent, so find it there { if (col.transform.parent.rigidbody2D) { if (col.transform.parent.GetComponent <GetDamage>()) { getDamage = col.transform.parent.GetComponent <GetDamage>(); damageable = true; } colliderSpeed = col.transform.parent.rigidbody2D.velocity.magnitude; } } if (damageable && !delaying) { if (attacking && attackTimer > 0 && (rigidbody2D.velocity.magnitude - colliderSpeed) > damageVelocity) //if launching { if (!col.collider.GetComponent <MiniCopterBlock>()) //don't hurt other copters { StartCoroutine(Delaying()); StartCoroutine(getDamage.SendDamage(baselineDamage, blockType)); } } else if (transform.localScale.x == 3 && (rigidbody2D.velocity.magnitude - colliderSpeed) > damageVelocity) //if being shot { StartCoroutine(Delaying()); StartCoroutine(getDamage.SendDamage(baselineDamage, blockType)); } } }
public IEnumerator DangerHighVoltage() { cols = Physics2D.OverlapCircleAll(transform.position, shockRadius); doDamage = new bool[cols.Length]; j = 0; while (j < cols.Length) { if (cols[j].GetComponent <GetDamage>()) { doDamage[j] = true; distFactor = 1 - Vector2.Distance(transform.position, cols[j].transform.position) / shockRadius; reducedRate = Mathf.RoundToInt(distFactor * stickerShock); GetDamage damageScript = cols[j].GetComponent <GetDamage>(); StartCoroutine(damageScript.SendDamage(reducedRate, weaponBlockScript.blockType)); } j++; } yield return(new WaitForSeconds(.2f)); StartCoroutine(DangerHighVoltage()); }
public void TakeDamage(float damage) => GetDamage?.Invoke(damage);
public void OnPlayerGetDamage() { GetDamage?.Invoke(); }
public IEnumerator FreezeIt() { Instantiate ( Resources.Load ("Prefabs/Effects/Frozesplosion"),transform.position,Quaternion.identity); freezeTimer = timeFrozen; allFrozen = Physics2D.OverlapCircleAll (transform.position, exRadius); allGameObjects = new GameObject[allFrozen.Length]; i = 0; foreach (Collider2D coller in allFrozen){ allGameObjects[i] = coller.gameObject; i++; } i = 0; foreach (Collider2D fro in allFrozen){ itsAPlayer = false; bPos = transform.position; thingPos = fro.transform.position; freDir = Vector3.Normalize(thingPos - bPos); dist2frozeSploder = Vector3.Distance(bPos,thingPos); //center to center distance RaycastHit2D[] rayThings = Physics2D.RaycastAll (bPos,freDir,dist2frozeSploder); foreach (RaycastHit2D rayThing in rayThings){ if (rayThing.collider.gameObject == fro.gameObject){ hitPointThing = rayThing.point; //world space point break; } } RaycastHit2D[] rayExps = Physics2D.RaycastAll (thingPos,-freDir,dist2frozeSploder); foreach (RaycastHit2D rayExp in rayExps){ if (rayExp.collider.gameObject == this.gameObject){ hitPointFro = rayExp.point; //world space point break; } } dist2frozeSploder = Vector3.Distance(hitPointFro,hitPointThing); //edge to edge distance if (icecle){ froMultiplier = 1f-Mathf.Exp (-1.25f*dist2frozeSploder); } else{ froMultiplier = 1f-Mathf.Exp (-.6f*dist2frozeSploder); } damage = Mathf.RoundToInt ( damageBaseline * (1f-froMultiplier) ); if (fro.GetComponent<GetDamage>()){ //this protects against double damage to gameobjects with a circle and a box collider (and triple to those also with a polygon collider!) j = 0; makeItHurt = true; while ( j < i ){ if (allGameObjects[i] == allGameObjects[j]){ makeItHurt = false; break; } j++; } if (makeItHurt){ getDamage = fro.GetComponent<GetDamage>(); StartCoroutine(getDamage.SendDamage(damage, weaponBlockScript.blockType)); } } if (fro.sharedMaterial){ //store its starting name, bounciness and friction for later use GatherAllKnowledge know = GameObject.Find ("theOmniscient").GetComponent<GatherAllKnowledge> (); k=0; while (k<know.numMats) { if (fro.sharedMaterial.name.Contains (know.allNames[k]) ){ startingName = know.allNames[k]; startingBounce = know.allBounciness[k]; startingFriction = know.allFriction[k]; break; } k++; } froFriction = froMultiplier * startingFriction; froBounce = froMultiplier * startingBounce; if (fro.transform.parent){ if (fro.transform.parent.parent){ if (fro.transform.parent.parent.CompareTag("Player")){ player = fro.transform.parent.parent.GetComponent<Player>(); itsAPlayer = true; } } else{ if (fro.transform.parent.CompareTag("Player")){ player = fro.transform.parent.GetComponent<Player>(); itsAPlayer = true; } else{ if (fro.CompareTag("Player")){ player = fro.GetComponent<Player>(); itsAPlayer = true; } } } } else{ if (fro.CompareTag("Player")){ player = fro.GetComponent<Player>(); itsAPlayer = true; } } if (itsAPlayer){ if (!player.onMyKnees){ startingJumpSpeed = player.startingJumpSpeed; startingRunningSpeed = player.startingRunningSpeed; startingMaxVelocity = player.startingMaxVelocity; } else{ startingJumpSpeed = player.startingJumpSpeed * .5f; startingRunningSpeed = player.startingRunningSpeed * .5f; startingMaxVelocity = player.startingMaxVelocity * .5f; } froJumpSpeed = froMultiplier * startingJumpSpeed; froRunningSpeed = froMultiplier * startingRunningSpeed; froMaxVelocity = froMultiplier * startingMaxVelocity; player.jumpSpeed = froJumpSpeed; player.runningSpeed = froRunningSpeed; player.maxVelocity.x = froMaxVelocity; } if (!fro.GetComponent<Unfreeze>()){ // if it doesn't already have the unfreeze, check to add if (fro.transform.parent){ //if there is a parent if (fro.transform.parent.parent){ //if there is a grandparent! fro.transform.parent.parent.gameObject.AddComponent<Unfreeze>(); unfreeze = fro.transform.parent.parent.GetComponent<Unfreeze>(); unfreeze.startingFriction = startingFriction; unfreeze.startingBounce = startingBounce; unfreeze.mydickiscold = true; fro.transform.parent.gameObject.AddComponent<Unfreeze>(); unfreeze = fro.transform.parent.GetComponent<Unfreeze>(); unfreeze.startingFriction = startingFriction; unfreeze.startingBounce = startingBounce; unfreeze.mydickiscold = true; fro.transform.gameObject.AddComponent<Unfreeze>(); unfreeze = fro.GetComponent<Unfreeze>(); unfreeze.startingFriction = startingFriction; unfreeze.startingBounce = startingBounce; unfreeze.mydickiscold = true; foreach (Collider2D col in fro.transform.parent.parent.GetComponents<Collider2D>()){ //slip up the grandparentparent colliders startingEnabled = col.enabled; col.enabled = false; col.sharedMaterial = GetMaterial (froFriction,froBounce,startingName); col.enabled = true; col.enabled = startingEnabled; } foreach (Collider2D col in fro.transform.parent.GetComponents<Collider2D>()){//and the parents startingEnabled = col.enabled; col.enabled = false; col.sharedMaterial = GetMaterial (froFriction,froBounce,startingName); col.enabled = true; col.enabled = startingEnabled; } foreach (Collider2D col in fro.GetComponents<Collider2D>()){ //and the thing startingEnabled = col.enabled; col.enabled = false; col.sharedMaterial = GetMaterial (froFriction,froBounce,startingName); col.enabled = true; col.enabled = startingEnabled; } } else{ //ok it's not on the grandparent, so we should add one to the parent fro.transform.parent.gameObject.AddComponent<Unfreeze>(); unfreeze = fro.transform.parent.GetComponent<Unfreeze>(); unfreeze.startingFriction = startingFriction; unfreeze.startingBounce = startingBounce; unfreeze.mydickiscold = true; fro.transform.gameObject.AddComponent<Unfreeze>(); unfreeze = fro.GetComponent<Unfreeze>(); unfreeze.startingFriction = startingFriction; unfreeze.startingBounce = startingBounce; unfreeze.mydickiscold = true; foreach (Collider2D col in fro.transform.parent.GetComponents<Collider2D>()){//and the parents startingEnabled = col.enabled; col.enabled = false; col.sharedMaterial = GetMaterial (froFriction,froBounce,startingName); col.enabled = true; col.enabled = startingEnabled; } foreach (Collider2D col in fro.GetComponents<Collider2D>()){ //and the thing startingEnabled = col.enabled; col.enabled = false; col.sharedMaterial = GetMaterial (froFriction,froBounce,startingName); col.enabled = true; col.enabled = startingEnabled; } } } else{ //so it's not on this gameobject, and it's there's no parent. add it fro.transform.gameObject.AddComponent<Unfreeze>(); unfreeze = fro.GetComponent<Unfreeze>(); unfreeze.startingFriction = startingFriction; unfreeze.startingBounce = startingBounce; unfreeze.mydickiscold = true; foreach (Collider2D col in fro.GetComponents<Collider2D>()){ //and the thing startingEnabled = col.enabled; col.enabled = false; col.sharedMaterial = GetMaterial (froFriction,froBounce,startingName); col.enabled = true; col.enabled = startingEnabled; } } } else{ //so it was here all along unfreeze = fro.GetComponent<Unfreeze>(); unfreeze.mydickiscold = true; if (fro.transform.parent){ //if there is a parent unfreeze = fro.transform.parent.GetComponent<Unfreeze>(); unfreeze.mydickiscold = true; if (fro.transform.parent.parent){ //if there is a grandparent! unfreeze = fro.transform.parent.parent.GetComponent<Unfreeze>(); unfreeze.mydickiscold = true; } } } } i++; } yield return null; Destroy(this.gameObject); }
public void TakeDamage(float damage) { hurtSound.Play(); GetDamage?.Invoke(damage); }
// Update is called once per frame void Update() { jPos = transform.position; if (char1) { p1Pos = character1.transform.position; dist2Player1 = Vector3.Distance (p1Pos,jPos); } if (char2){ p2Pos = character2.transform.position; dist2Player2 = Vector3.Distance (p2Pos,jPos); } if ( dist2Player1 <= dist2Player2 ){ pPos = p1Pos; dist2Player = dist2Player1; } else{ pPos = p2Pos; dist2Player = dist2Player2; } aDir = Vector3.Normalize(pPos - jPos); vely = rigidbody2D.velocity.y; standing = DetectFloor (); Animate (standing,aDir); //Debug.DrawLine (transform.position, transform.position + transform.localScale.x * Vector3.right * dangerZone); //////////ATTACKING SCRIPT//////////////// if (dist2Player < dangerZone && allowJump) { ready2Attack = true; // time-based if (standing){ attack = true; //single frame (and really, only within the frame because it gets reset the same frame) } } if (attack){ allowJump = false; attack = false; ready2Attack = true; jumpTimer = time2Jump; if (aDir.x > 0 ){ rigidbody2D.AddForce (attackVectorR * aForce); } else if (aDir.x < 0 ){ rigidbody2D.AddForce (attackVectorL * aForce); } } if (ready2Attack || spinAttacking || stompAttacking){ if (!spinAttacking && !stompAttacking && rigidbody2D.velocity.y>1f){ spot1 = new Vector2( Mathf.Cos(Mathf.Deg2Rad * 45f) * transform.localScale.x, Mathf.Sin(Mathf.Deg2Rad * 45f) ) * spinDist + new Vector2(transform.position.x,transform.position.y); spot2 = new Vector2( Mathf.Cos(Mathf.Deg2Rad * 80f) * transform.localScale.x, Mathf.Sin(Mathf.Deg2Rad * 80f) ) * spinDist + new Vector2(transform.position.x,transform.position.y); Debug.DrawLine (transform.position, new Vector3 (spot1.x,spot1.y,0)); Debug.DrawLine (transform.position, new Vector3 (spot2.x,spot2.y,0)); aboveObjects1 = Physics2D.LinecastAll(transform.position,spot1); aboveObjects2 = Physics2D.LinecastAll(transform.position,spot2); aboveObjects = aboveObjects1.Concat(aboveObjects2).ToArray(); foreach (RaycastHit2D above in aboveObjects){ if (hurtThings.Contains (above.collider.tag)){ spinAttack = true; spinAttacking = true; spinTimer = time2Spin; break; } } } if (spinAttack){ rigidbody2D.fixedAngle = false; spinAttack = false; } if (spinAttacking){ if (spinTimer>0){ rigidbody2D.angularVelocity = 2000f; spinTimer -= Time.deltaTime; hitObjects = Physics2D.OverlapCircleAll(transform.position,.115f); foreach (Collider2D hit in hitObjects){ if (hit.GetComponent<GetDamage>()){ getDamage = hit.GetComponent<GetDamage>(); getDamage.StartCoroutine(getDamage.SendDamage(spinDamage,blockType)); spinTimer = 0f; rigidbody2D.velocity = new Vector2 (0,0); rigidbody2D.AddForce ( Vector3.Normalize(new Vector3(-(transform.localScale.x * 3),1,0)) * 155f); break; } else if (rigidbody2D.velocity.y<-2f){ spinTimer = 0f; } } } if (spinTimer <= 0 && rotateTimer <= 0 ){ ready2Attack = false; rotateTimer = time2Rotate; } if (rotateTimer>0){ rotateTimer -= Time.deltaTime; Quaternion.Slerp( transform.rotation , Quaternion.identity , Time.deltaTime * rotoSpeed); //slerp back to upright rotation and fix angle if (rotateTimer<=0 || (Mathf.Abs (transform.rotation.eulerAngles.z) < 2f && Mathf.Abs (rigidbody2D.angularVelocity)<2f) ){ spinAttacking = false; transform.rotation = Quaternion.identity; rigidbody2D.fixedAngle = true; recoveryTimer = time2Recover; } } } //END SPINNING ATTACK //START STOMPING ATTACK if (!stompAttacking && !spinAttacking && rigidbody2D.velocity.y<-.1f){ spot3 = new Vector2( Mathf.Cos(Mathf.Deg2Rad * 50f) * transform.localScale.x, -Mathf.Sin(Mathf.Deg2Rad * 50f) ) * stompDist + new Vector2(transform.position.x,transform.position.y); spot4 = new Vector2( Mathf.Cos(Mathf.Deg2Rad * 65f) * transform.localScale.x, -Mathf.Sin(Mathf.Deg2Rad * 65f) ) * stompDist + new Vector2(transform.position.x,transform.position.y); spot5 = new Vector2( Mathf.Cos(Mathf.Deg2Rad * 80f) * transform.localScale.x, -Mathf.Sin(Mathf.Deg2Rad * 80f) ) * stompDist + new Vector2(transform.position.x,transform.position.y); Debug.DrawLine (transform.position, new Vector3 (spot3.x,spot3.y,0)); Debug.DrawLine (transform.position, new Vector3 (spot4.x,spot4.y,0)); Debug.DrawLine (transform.position, new Vector3 (spot5.x,spot5.y,0)); belowObjects1 = Physics2D.LinecastAll(transform.position,spot3); belowObjects2 = Physics2D.LinecastAll(transform.position,spot4); belowObjects3 = Physics2D.LinecastAll(transform.position,spot5); belowObjects = belowObjects1.Concat(belowObjects2).ToArray(); belowObjects = belowObjects.Concat(belowObjects3).ToArray(); foreach (RaycastHit2D below in belowObjects){ if (hurtThings.Contains (below.collider.tag)){ stompAttack = true; stompAttacking = true; stompTimer = time2Stomp; break; } } } if (stompAttack){ rigidbody2D.AddForce (aDir * stompForce); if (rigidbody2D.velocity.x>0 && aDir.x<0){ rigidbody2D.AddForce (-Vector2.right * 80f); } else if (rigidbody2D.velocity.x<0 && aDir.x>0){ rigidbody2D.AddForce (Vector2.right * 80f); } stompAttack = false; } if (stompAttacking){ if (stompTimer>0){ hitObjects = Physics2D.OverlapAreaAll(botLeft,topRight); foreach (Collider2D hit in hitObjects){ if (hit.GetComponent<GetDamage>()){ getDamage = hit.GetComponent<GetDamage>(); getDamage.StartCoroutine(getDamage.SendDamage(spinDamage,blockType)); stompTimer = 0f; break; } else if (hit.CompareTag("Platform")){ stompTimer = 0f; } } } if (stompTimer>0){ stompTimer -= Time.deltaTime; } if (stompTimer<=0){ ready2Attack = false; stompAttacking = false; recoveryTimer = time2Recover; } } } if (recoveryTimer>0){ recoveryTimer -= Time.deltaTime; } //END STOMP ATTACK //////END ATTACKING SCRIPT////// //Jump Around if (allowJump && standing){ allowJump = false; jumpTimer = time2Jump; if (aDir.x > 0){ rigidbody2D.AddForce (jumpVectorR * jForce); } else if (aDir.x < 0){ rigidbody2D.AddForce (jumpVectorL * jForce); } } if (standing && rigidbody2D.velocity.y<.1f){ jumpTimer -= Time.deltaTime; if (jumpTimer<=0 && recoveryTimer<=0){ allowJump = true; } } }
// Use this for initialization void Awake() { blockType = -2; startingHealth = 10; currentHealth = startingHealth; startingBounce = rigidbody2D.collider2D.sharedMaterial.bounciness; startingFriction = rigidbody2D.collider2D.sharedMaterial.friction; char1 = false; char2 = false; dist2Player1 = 100f; dist2Player2 = 100f; if (GameObject.Find ("Hero1")) { char1 = true; character1 = GameObject.Find ("Hero1"); } if (GameObject.Find ("Hero2")){ char2 = true; character2 = GameObject.Find ("Hero2"); } getDamage = GetComponent<GetDamage> (); dangerZone = 2.5f; spinDist = .6f; stompDist = 3f; ready2Attack = false; attack = false; attackVectorR = Vector3.Normalize(new Vector3 (1, 4,0)); attackVectorL = Vector3.Normalize(new Vector3 (-1, 4,0)); aForce = 300f; allowJump = true; time2Jump = 1f; jForce = 200f; jumpVectorR = Vector3.Normalize(new Vector3 (1, 2,0)); jumpVectorL = Vector3.Normalize(new Vector3 (-1, 2,0)); standing = false; hurtThings = new string[] {"Player","Blank"}; spinDamage = 15; stompDamage = 25; stompForce = 400f; time2Stomp = 1f; stompTimer = 0f; time2Spin = 1f; spinTimer = 0f; spinAttack = false; spinAttacking = false; time2Rotate = .4f; rotateTimer = time2Rotate; rotoSpeed = 30f; time2Recover = 1.5f; recoveryTimer = 0f; startReRotating = false; }
/*Animation BreakDown * 0 - Standing Still * 1 - Running * 2 - Squatting * 3 - Reverse Squatting * 4 - Squatting Still * 5 - Squat Running */ void Awake() { controller = GetComponent<Controller> (); getDamage = GetComponent<GetDamage> (); allKnow = GameObject.Find ("theOmniscient").GetComponent<GatherAllKnowledge> (); crouching = false; uncrouching = false; onMyKnees = false; Physics2D.IgnoreLayerCollision (8, 8); conAnchs = new Vector2[] { new Vector2 (0.025f,0.37f), new Vector2 (0.025f, 0.315f), new Vector2 (0.025f, 0.2605f), new Vector2 (0.025f, 0.2055f), new Vector2 (0.015f, 0.15f), }; if (GameObject.Find ("CheckPoints")) { checkPoint = GameObject.Find ("CheckPoints").GetComponent<CheckPoint>(); } char1 = false; char2 = false; teleHovering = false; copterHovering = false; recoRotoSpeed = 25f; angleTol = 3f; liftForce = 75f; jetSpeed = 300f; unitTimeFrame = .083f; platforms = new Collider2D[20]; minMoveRad = .4f; if (GameObject.Find("ZoomZone")){ zoomZone = GameObject.Find("ZoomZone").GetComponent<ZoomZone>(); } if (gameObject.name == "Hero1"){ char1 = true; hud = GameObject.Find("HUD1").GetComponent<HUD> (); healthBar = GameObject.Find ("HealthBar1").GetComponent<HealthBar> (); arm = GameObject.Find("Arm1"); shield = GameObject.Find("Shield1"); hammer = GameObject.Find("Hammer1"); tractorBeam = GameObject.Find("TractorBeam1"); weaponDetectorScript = GameObject.Find ("WeaponDetector1").GetComponent<WeaponDetectorScript> (); chargeDisplay = GameObject.Find ("ChargeBar1").GetComponent<ChargeDisplay> (); } else{ char2 = true; hud = GameObject.Find("HUD2").GetComponent<HUD> (); healthBar = GameObject.Find ("HealthBar2").GetComponent<HealthBar> (); arm = GameObject.Find("Arm2"); shield = GameObject.Find("Shield2"); hammer = GameObject.Find("Hammer2"); tractorBeam = GameObject.Find("TractorBeam2"); weaponDetectorScript = GameObject.Find ("WeaponDetector2").GetComponent<WeaponDetectorScript> (); chargeDisplay = GameObject.Find ("ChargeBar2").GetComponent<ChargeDisplay> (); } polyCols = GetComponents<PolygonCollider2D> (); cirCol = GetComponent<CircleCollider2D> (); hamCol = hammer.GetComponent<BoxCollider2D> (); shieldCol = shield.GetComponent<PolygonCollider2D> (); tractorBeamCol = tractorBeam.GetComponent<PolygonCollider2D> (); weaponCol = weaponDetectorScript.GetComponent<CircleCollider2D> (); spriteArm = arm.GetComponent<SpriteRenderer> (); spriteShield = shield.GetComponent<SpriteRenderer> (); spriteHero = GetComponent<SpriteRenderer> (); spriteHammer = hammer.GetComponent<SpriteRenderer> (); startingBounce = cirCol.sharedMaterial.bounciness; startingFriction = cirCol.sharedMaterial.friction; armRotateScript = arm.GetComponent<ArmRotate> (); armRot = arm.transform.rotation; armHinge = arm.GetComponent<HingeJoint2D>(); shieldHinge = shield.GetComponent<HingeJoint2D>(); hammerHinge = hammer.GetComponent<HingeJoint2D> (); alive = true; //transform.position = Vector3.zero; if (Application.loadedLevelName == "BattleArena"){ spawnSpots = new Vector3[6]; spawnSpots[0] = new Vector3 (0f,-2f,0f); spawnSpots [1] = new Vector3 (-2f,-1f,0f); spawnSpots [2] = new Vector3 (2f,-1f,0f); spawnSpots [3] = new Vector3 (0f,0f,0f); spawnSpots [4] = new Vector3 (0f,-2f,0f); spawnSpots [5] = new Vector3 (0f,-2f,0f); } else if (Application.loadedLevelName == "BattleShrine"){ spawnSpots = new Vector3[6]; spawnSpots [0] = new Vector3 (0f,2.5f,0f); spawnSpots [1] = new Vector3 (-1f,0f,0f); spawnSpots [2] = new Vector3 (1f,0f,0f); spawnSpots [3] = new Vector3 (0f,-2.5f,0f); spawnSpots [4] = new Vector3 (-3.5f,-.75f,0f); spawnSpots [5] = new Vector3 (3.5f,-.75f,0f); } else{ spawnSpots = new Vector3[6]; spawnSpots [0] = new Vector3 (0f,-2f,0f); spawnSpots [1] = new Vector3 (-2f,-1f,0f); spawnSpots [2] = new Vector3 (2f,-1f,0f); spawnSpots [3] = new Vector3 (0f,0f,0f); spawnSpots [4] = new Vector3 (0f,-2f,0f); spawnSpots [5] = new Vector3 (0f,-2f,0f); } wallJumpLagTime = .7f; runningVelThresh = .3f; runningCrouchVelThresh = .1f; wallDelay = false; heroAnimator = GetComponent<Animator>(); time2Respawn = 2f; startingHealth = 100; fallTimeDelay = 1f; runningSpeed = 7.5f; floatingSpeed = runningSpeed; jumpSpeed = 200f; fallSpeed = -50f; maxVelocity = new Vector2 (2f, 5f); maxFloatVelocity = new Vector2 (2.5f, 2.5f); floorDetectionBoxHeights = new Vector2 (0.023f,0.2f); forceX = 0; forceY = 0; i = 0; damage = 0; startingJumpSpeed = jumpSpeed; startingRunningSpeed = runningSpeed; startingFallSpeed = fallSpeed; startingMaxVelocity = maxVelocity.x; followP1 = true; }
//explode some time after this block is fired public IEnumerator BlowMe() { yield return new WaitForSeconds (time2Blow); allObjects = Physics2D.OverlapCircleAll (transform.position,exRadius); allGameObjects = new GameObject[allObjects.Length]; i = 0; foreach (Collider2D coller in allObjects){ allGameObjects[i] = coller.gameObject; i++; } i = 0; foreach (Collider2D thing in allObjects){ if (!dontBlowStrings.Contains(thing.name) && thing.gameObject!=gameObject){ bPos = transform.position; thingPos = thing.transform.position; exDir = Vector3.Normalize(thingPos - bPos); dist2exploder = Vector3.Distance(bPos,thingPos); /*rayThings = Physics2D.RaycastAll (bPos,exDir,dist2exploder); foreach (RaycastHit2D rayThing in rayThings){ if (rayThing.collider.gameObject == thing.gameObject){ hitPointThing = rayThing.point; break; } } rayExps = Physics2D.RaycastAll (thingPos,-exDir,dist2exploder); foreach (RaycastHit2D rayExp in rayExps){ if (rayExp.collider.gameObject == this.gameObject){ hitPointExp = rayExp.point; break; } } dist2exploder = Vector3.Distance(hitPointExp,hitPointThing); */ if (dist2exploder<0){ dist2exploder=0; } exMultiplier = Mathf.Exp(-.6f * dist2exploder); exForce = exForceBaseline * exMultiplier; damage = Mathf.RoundToInt ( damageBaseline * exMultiplier ); if (thing.GetComponent<GetDamage>()){ j = 0; makeItHurt = true; while ( j < i ){ if (allGameObjects[i] == allGameObjects[j]){ makeItHurt = false; } j++; } if (makeItHurt){ getDamage = thing.GetComponent<GetDamage>(); StartCoroutine(getDamage.SendDamage(damage,weaponBlockScript.blockType)); if (thing.rigidbody2D){ thing.rigidbody2D.AddForce(exDir * exForce); } } } else{ if (thing.rigidbody2D){ thing.rigidbody2D.AddForce(exDir * exForce); } } } i++; } GameObject expo = Instantiate ( Resources.Load("Prefabs/Effects/Explosion"),this.transform.position,this.transform.rotation) as GameObject; expo.transform.localScale = Vector3.one * 25; Destroy (this.gameObject); }
void OnCollisionEnter2D(Collision2D col) { damageable = false; if (col.rigidbody) { if (col.gameObject.GetComponent<GetDamage>()){ getDamage = col.gameObject.GetComponent<GetDamage>(); damageable = true; } colliderSpeed = col.rigidbody.velocity.magnitude; } else if (col.transform.parent){ //so if this is a child gameobject with a collider, its rigidbody is on the parent, so find it there if (col.transform.parent.rigidbody2D){ if (col.transform.parent.GetComponent<GetDamage>()){ getDamage = col.transform.parent.GetComponent<GetDamage>(); damageable = true; } colliderSpeed = col.transform.parent.rigidbody2D.velocity.magnitude; } } if (damageable && !delaying){ if (attacking && attackTimer>0 && (rigidbody2D.velocity.magnitude - colliderSpeed) > damageVelocity){ //if launching if (!col.collider.GetComponent<MiniCopterBlock>()){ //don't hurt other copters StartCoroutine(Delaying()); StartCoroutine(getDamage.SendDamage(baselineDamage,blockType)); } } else if (transform.localScale.x==3 && (rigidbody2D.velocity.magnitude - colliderSpeed) > damageVelocity){ //if being shot StartCoroutine(Delaying()); StartCoroutine(getDamage.SendDamage(baselineDamage,blockType)); } } }
// Update is called once per frame void Update() { jPos = transform.position; if (char1) { p1Pos = character1.transform.position; dist2Player1 = Vector3.Distance(p1Pos, jPos); } if (char2) { p2Pos = character2.transform.position; dist2Player2 = Vector3.Distance(p2Pos, jPos); } if (dist2Player1 <= dist2Player2) { pPos = p1Pos; dist2Player = dist2Player1; } else { pPos = p2Pos; dist2Player = dist2Player2; } aDir = Vector3.Normalize(pPos - jPos); vely = rigidbody2D.velocity.y; standing = DetectFloor(); Animate(standing, aDir); //Debug.DrawLine (transform.position, transform.position + transform.localScale.x * Vector3.right * dangerZone); //////////ATTACKING SCRIPT//////////////// if (dist2Player < dangerZone && allowJump) { ready2Attack = true; // time-based if (standing) { attack = true; //single frame (and really, only within the frame because it gets reset the same frame) } } if (attack) { allowJump = false; attack = false; ready2Attack = true; jumpTimer = time2Jump; if (aDir.x > 0) { rigidbody2D.AddForce(attackVectorR * aForce); } else if (aDir.x < 0) { rigidbody2D.AddForce(attackVectorL * aForce); } } if (ready2Attack || spinAttacking || stompAttacking) { if (!spinAttacking && !stompAttacking && rigidbody2D.velocity.y > 1f) { spot1 = new Vector2(Mathf.Cos(Mathf.Deg2Rad * 45f) * transform.localScale.x, Mathf.Sin(Mathf.Deg2Rad * 45f)) * spinDist + new Vector2(transform.position.x, transform.position.y); spot2 = new Vector2(Mathf.Cos(Mathf.Deg2Rad * 80f) * transform.localScale.x, Mathf.Sin(Mathf.Deg2Rad * 80f)) * spinDist + new Vector2(transform.position.x, transform.position.y); Debug.DrawLine(transform.position, new Vector3(spot1.x, spot1.y, 0)); Debug.DrawLine(transform.position, new Vector3(spot2.x, spot2.y, 0)); aboveObjects1 = Physics2D.LinecastAll(transform.position, spot1); aboveObjects2 = Physics2D.LinecastAll(transform.position, spot2); aboveObjects = aboveObjects1.Concat(aboveObjects2).ToArray(); foreach (RaycastHit2D above in aboveObjects) { if (hurtThings.Contains(above.collider.tag)) { spinAttack = true; spinAttacking = true; spinTimer = time2Spin; break; } } } if (spinAttack) { rigidbody2D.fixedAngle = false; spinAttack = false; } if (spinAttacking) { if (spinTimer > 0) { rigidbody2D.angularVelocity = 2000f; spinTimer -= Time.deltaTime; hitObjects = Physics2D.OverlapCircleAll(transform.position, .115f); foreach (Collider2D hit in hitObjects) { if (hit.GetComponent <GetDamage>()) { getDamage = hit.GetComponent <GetDamage>(); getDamage.StartCoroutine(getDamage.SendDamage(spinDamage, blockType)); spinTimer = 0f; rigidbody2D.velocity = new Vector2(0, 0); rigidbody2D.AddForce(Vector3.Normalize(new Vector3(-(transform.localScale.x * 3), 1, 0)) * 155f); break; } else if (rigidbody2D.velocity.y < -2f) { spinTimer = 0f; } } } if (spinTimer <= 0 && rotateTimer <= 0) { ready2Attack = false; rotateTimer = time2Rotate; } if (rotateTimer > 0) { rotateTimer -= Time.deltaTime; Quaternion.Slerp(transform.rotation, Quaternion.identity, Time.deltaTime * rotoSpeed); //slerp back to upright rotation and fix angle if (rotateTimer <= 0 || (Mathf.Abs(transform.rotation.eulerAngles.z) < 2f && Mathf.Abs(rigidbody2D.angularVelocity) < 2f)) { spinAttacking = false; transform.rotation = Quaternion.identity; rigidbody2D.fixedAngle = true; recoveryTimer = time2Recover; } } } //END SPINNING ATTACK //START STOMPING ATTACK if (!stompAttacking && !spinAttacking && rigidbody2D.velocity.y < -.1f) { spot3 = new Vector2(Mathf.Cos(Mathf.Deg2Rad * 50f) * transform.localScale.x, -Mathf.Sin(Mathf.Deg2Rad * 50f)) * stompDist + new Vector2(transform.position.x, transform.position.y); spot4 = new Vector2(Mathf.Cos(Mathf.Deg2Rad * 65f) * transform.localScale.x, -Mathf.Sin(Mathf.Deg2Rad * 65f)) * stompDist + new Vector2(transform.position.x, transform.position.y); spot5 = new Vector2(Mathf.Cos(Mathf.Deg2Rad * 80f) * transform.localScale.x, -Mathf.Sin(Mathf.Deg2Rad * 80f)) * stompDist + new Vector2(transform.position.x, transform.position.y); Debug.DrawLine(transform.position, new Vector3(spot3.x, spot3.y, 0)); Debug.DrawLine(transform.position, new Vector3(spot4.x, spot4.y, 0)); Debug.DrawLine(transform.position, new Vector3(spot5.x, spot5.y, 0)); belowObjects1 = Physics2D.LinecastAll(transform.position, spot3); belowObjects2 = Physics2D.LinecastAll(transform.position, spot4); belowObjects3 = Physics2D.LinecastAll(transform.position, spot5); belowObjects = belowObjects1.Concat(belowObjects2).ToArray(); belowObjects = belowObjects.Concat(belowObjects3).ToArray(); foreach (RaycastHit2D below in belowObjects) { if (hurtThings.Contains(below.collider.tag)) { stompAttack = true; stompAttacking = true; stompTimer = time2Stomp; break; } } } if (stompAttack) { rigidbody2D.AddForce(aDir * stompForce); if (rigidbody2D.velocity.x > 0 && aDir.x < 0) { rigidbody2D.AddForce(-Vector2.right * 80f); } else if (rigidbody2D.velocity.x < 0 && aDir.x > 0) { rigidbody2D.AddForce(Vector2.right * 80f); } stompAttack = false; } if (stompAttacking) { if (stompTimer > 0) { hitObjects = Physics2D.OverlapAreaAll(botLeft, topRight); foreach (Collider2D hit in hitObjects) { if (hit.GetComponent <GetDamage>()) { getDamage = hit.GetComponent <GetDamage>(); getDamage.StartCoroutine(getDamage.SendDamage(spinDamage, blockType)); stompTimer = 0f; break; } else if (hit.CompareTag("Platform")) { stompTimer = 0f; } } } if (stompTimer > 0) { stompTimer -= Time.deltaTime; } if (stompTimer <= 0) { ready2Attack = false; stompAttacking = false; recoveryTimer = time2Recover; } } } if (recoveryTimer > 0) { recoveryTimer -= Time.deltaTime; } //END STOMP ATTACK //////END ATTACKING SCRIPT////// //Jump Around if (allowJump && standing) { allowJump = false; jumpTimer = time2Jump; if (aDir.x > 0) { rigidbody2D.AddForce(jumpVectorR * jForce); } else if (aDir.x < 0) { rigidbody2D.AddForce(jumpVectorL * jForce); } } if (standing && rigidbody2D.velocity.y < .1f) { jumpTimer -= Time.deltaTime; if (jumpTimer <= 0 && recoveryTimer <= 0) { allowJump = true; } } }
public IEnumerator FreezeIt() { Instantiate(Resources.Load("Prefabs/Effects/Frozesplosion"), transform.position, Quaternion.identity); freezeTimer = timeFrozen; allFrozen = Physics2D.OverlapCircleAll(transform.position, exRadius); allGameObjects = new GameObject[allFrozen.Length]; i = 0; foreach (Collider2D coller in allFrozen) { allGameObjects[i] = coller.gameObject; i++; } i = 0; foreach (Collider2D fro in allFrozen) { itsAPlayer = false; bPos = transform.position; thingPos = fro.transform.position; freDir = Vector3.Normalize(thingPos - bPos); dist2frozeSploder = Vector3.Distance(bPos, thingPos); //center to center distance RaycastHit2D[] rayThings = Physics2D.RaycastAll(bPos, freDir, dist2frozeSploder); foreach (RaycastHit2D rayThing in rayThings) { if (rayThing.collider.gameObject == fro.gameObject) { hitPointThing = rayThing.point; //world space point break; } } RaycastHit2D[] rayExps = Physics2D.RaycastAll(thingPos, -freDir, dist2frozeSploder); foreach (RaycastHit2D rayExp in rayExps) { if (rayExp.collider.gameObject == this.gameObject) { hitPointFro = rayExp.point; //world space point break; } } dist2frozeSploder = Vector3.Distance(hitPointFro, hitPointThing); //edge to edge distance if (icecle) { froMultiplier = 1f - Mathf.Exp(-1.25f * dist2frozeSploder); } else { froMultiplier = 1f - Mathf.Exp(-.6f * dist2frozeSploder); } damage = Mathf.RoundToInt(damageBaseline * (1f - froMultiplier)); if (fro.GetComponent <GetDamage>()) //this protects against double damage to gameobjects with a circle and a box collider (and triple to those also with a polygon collider!) { j = 0; makeItHurt = true; while (j < i) { if (allGameObjects[i] == allGameObjects[j]) { makeItHurt = false; break; } j++; } if (makeItHurt) { getDamage = fro.GetComponent <GetDamage>(); StartCoroutine(getDamage.SendDamage(damage, weaponBlockScript.blockType)); } } if (fro.sharedMaterial) //store its starting name, bounciness and friction for later use { GatherAllKnowledge know = GameObject.Find("theOmniscient").GetComponent <GatherAllKnowledge> (); k = 0; while (k < know.numMats) { if (fro.sharedMaterial.name.Contains(know.allNames[k])) { startingName = know.allNames[k]; startingBounce = know.allBounciness[k]; startingFriction = know.allFriction[k]; break; } k++; } froFriction = froMultiplier * startingFriction; froBounce = froMultiplier * startingBounce; if (fro.transform.parent) { if (fro.transform.parent.parent) { if (fro.transform.parent.parent.CompareTag("Player")) { player = fro.transform.parent.parent.GetComponent <Player>(); itsAPlayer = true; } } else { if (fro.transform.parent.CompareTag("Player")) { player = fro.transform.parent.GetComponent <Player>(); itsAPlayer = true; } else { if (fro.CompareTag("Player")) { player = fro.GetComponent <Player>(); itsAPlayer = true; } } } } else { if (fro.CompareTag("Player")) { player = fro.GetComponent <Player>(); itsAPlayer = true; } } if (itsAPlayer) { if (!player.onMyKnees) { startingJumpSpeed = player.startingJumpSpeed; startingRunningSpeed = player.startingRunningSpeed; startingMaxVelocity = player.startingMaxVelocity; } else { startingJumpSpeed = player.startingJumpSpeed * .5f; startingRunningSpeed = player.startingRunningSpeed * .5f; startingMaxVelocity = player.startingMaxVelocity * .5f; } froJumpSpeed = froMultiplier * startingJumpSpeed; froRunningSpeed = froMultiplier * startingRunningSpeed; froMaxVelocity = froMultiplier * startingMaxVelocity; player.jumpSpeed = froJumpSpeed; player.runningSpeed = froRunningSpeed; player.maxVelocity.x = froMaxVelocity; } if (!fro.GetComponent <Unfreeze>()) // if it doesn't already have the unfreeze, check to add { if (fro.transform.parent) //if there is a parent { if (fro.transform.parent.parent) //if there is a grandparent! { fro.transform.parent.parent.gameObject.AddComponent <Unfreeze>(); unfreeze = fro.transform.parent.parent.GetComponent <Unfreeze>(); unfreeze.startingFriction = startingFriction; unfreeze.startingBounce = startingBounce; unfreeze.mydickiscold = true; fro.transform.parent.gameObject.AddComponent <Unfreeze>(); unfreeze = fro.transform.parent.GetComponent <Unfreeze>(); unfreeze.startingFriction = startingFriction; unfreeze.startingBounce = startingBounce; unfreeze.mydickiscold = true; fro.transform.gameObject.AddComponent <Unfreeze>(); unfreeze = fro.GetComponent <Unfreeze>(); unfreeze.startingFriction = startingFriction; unfreeze.startingBounce = startingBounce; unfreeze.mydickiscold = true; foreach (Collider2D col in fro.transform.parent.parent.GetComponents <Collider2D>()) //slip up the grandparentparent colliders { startingEnabled = col.enabled; col.enabled = false; col.sharedMaterial = GetMaterial(froFriction, froBounce, startingName); col.enabled = true; col.enabled = startingEnabled; } foreach (Collider2D col in fro.transform.parent.GetComponents <Collider2D>()) //and the parents { startingEnabled = col.enabled; col.enabled = false; col.sharedMaterial = GetMaterial(froFriction, froBounce, startingName); col.enabled = true; col.enabled = startingEnabled; } foreach (Collider2D col in fro.GetComponents <Collider2D>()) //and the thing { startingEnabled = col.enabled; col.enabled = false; col.sharedMaterial = GetMaterial(froFriction, froBounce, startingName); col.enabled = true; col.enabled = startingEnabled; } } else //ok it's not on the grandparent, so we should add one to the parent { fro.transform.parent.gameObject.AddComponent <Unfreeze>(); unfreeze = fro.transform.parent.GetComponent <Unfreeze>(); unfreeze.startingFriction = startingFriction; unfreeze.startingBounce = startingBounce; unfreeze.mydickiscold = true; fro.transform.gameObject.AddComponent <Unfreeze>(); unfreeze = fro.GetComponent <Unfreeze>(); unfreeze.startingFriction = startingFriction; unfreeze.startingBounce = startingBounce; unfreeze.mydickiscold = true; foreach (Collider2D col in fro.transform.parent.GetComponents <Collider2D>()) //and the parents { startingEnabled = col.enabled; col.enabled = false; col.sharedMaterial = GetMaterial(froFriction, froBounce, startingName); col.enabled = true; col.enabled = startingEnabled; } foreach (Collider2D col in fro.GetComponents <Collider2D>()) //and the thing { startingEnabled = col.enabled; col.enabled = false; col.sharedMaterial = GetMaterial(froFriction, froBounce, startingName); col.enabled = true; col.enabled = startingEnabled; } } } else //so it's not on this gameobject, and it's there's no parent. add it { fro.transform.gameObject.AddComponent <Unfreeze>(); unfreeze = fro.GetComponent <Unfreeze>(); unfreeze.startingFriction = startingFriction; unfreeze.startingBounce = startingBounce; unfreeze.mydickiscold = true; foreach (Collider2D col in fro.GetComponents <Collider2D>()) //and the thing { startingEnabled = col.enabled; col.enabled = false; col.sharedMaterial = GetMaterial(froFriction, froBounce, startingName); col.enabled = true; col.enabled = startingEnabled; } } } else //so it was here all along { unfreeze = fro.GetComponent <Unfreeze>(); unfreeze.mydickiscold = true; if (fro.transform.parent) //if there is a parent { unfreeze = fro.transform.parent.GetComponent <Unfreeze>(); unfreeze.mydickiscold = true; if (fro.transform.parent.parent) //if there is a grandparent! { unfreeze = fro.transform.parent.parent.GetComponent <Unfreeze>(); unfreeze.mydickiscold = true; } } } } i++; } yield return(null); Destroy(this.gameObject); }
// Use this for initialization void Awake() { blockType = -2; startingHealth = 10; currentHealth = startingHealth; startingBounce = rigidbody2D.collider2D.sharedMaterial.bounciness; startingFriction = rigidbody2D.collider2D.sharedMaterial.friction; char1 = false; char2 = false; dist2Player1 = 100f; dist2Player2 = 100f; if (GameObject.Find("Hero1")) { char1 = true; character1 = GameObject.Find("Hero1"); } if (GameObject.Find("Hero2")) { char2 = true; character2 = GameObject.Find("Hero2"); } getDamage = GetComponent <GetDamage> (); dangerZone = 2.5f; spinDist = .6f; stompDist = 3f; ready2Attack = false; attack = false; attackVectorR = Vector3.Normalize(new Vector3(1, 4, 0)); attackVectorL = Vector3.Normalize(new Vector3(-1, 4, 0)); aForce = 300f; allowJump = true; time2Jump = 1f; jForce = 200f; jumpVectorR = Vector3.Normalize(new Vector3(1, 2, 0)); jumpVectorL = Vector3.Normalize(new Vector3(-1, 2, 0)); standing = false; hurtThings = new string[] { "Player", "Blank" }; spinDamage = 15; stompDamage = 25; stompForce = 400f; time2Stomp = 1f; stompTimer = 0f; time2Spin = 1f; spinTimer = 0f; spinAttack = false; spinAttacking = false; time2Rotate = .4f; rotateTimer = time2Rotate; rotoSpeed = 30f; time2Recover = 1.5f; recoveryTimer = 0f; startReRotating = false; }
public IEnumerator BlowYourLoad() { yield return(new WaitForEndOfFrame()); allObjects = Physics2D.OverlapCircleAll(transform.position, exRadius); allGameObjects = new GameObject[allObjects.Length]; i = 0; foreach (Collider2D coller in allObjects) { allGameObjects[i] = coller.gameObject; i++; } i = 0; foreach (Collider2D thing in allObjects) { if (!dontBlowStrings.Contains(thing.name) && thing.gameObject != gameObject) { Vector3 bPos = transform.position; Vector3 thingPos = thing.transform.position; Vector3 exDir = Vector3.Normalize(thingPos - bPos); float dist2exploder = Vector3.Distance(bPos, thingPos); /*RaycastHit2D[] rayThings = Physics2D.RaycastAll (bPos,exDir,dist2exploder); * foreach (RaycastHit2D rayThing in rayThings){ * if (rayThing.collider.gameObject == thing.gameObject){ * hitPointThing = rayThing.point; * break; * } * } * RaycastHit2D[] rayExps = Physics2D.RaycastAll (thingPos,-exDir,dist2exploder); * foreach (RaycastHit2D rayExp in rayExps){ * if (rayExp.collider.gameObject == this.gameObject){ * hitPointExp = rayExp.point; * break; * } * } * * dist2exploder = Vector3.Distance(hitPointExp,hitPointThing); */ if (dist2exploder < 0) { dist2exploder = 0; } exMultiplier = Mathf.Exp(-.6f * dist2exploder); exForce = exForceBaseline * exMultiplier; damage = Mathf.RoundToInt(damageBaseline * exMultiplier); if (thing.GetComponent <GetDamage>()) { j = 0; makeItHurt = true; while (j < i) { if (allGameObjects[i] == allGameObjects[j]) { makeItHurt = false; } j++; } if (makeItHurt) { getDamage = thing.GetComponent <GetDamage>(); StartCoroutine(getDamage.SendDamage(damage, weaponBlockScript.blockType)); if (thing.rigidbody2D) { thing.rigidbody2D.AddForce(exDir * exForce); } } } //only addforce to things that are not locked in blocks/copters else { if (thing.rigidbody2D) { thing.rigidbody2D.AddForce(exDir * exForce); } } } i++; } GameObject expo = Instantiate(Resources.Load("Prefabs/Effects/Explosion"), this.transform.position, this.transform.rotation) as GameObject; expo.transform.localScale = Vector3.one * 25; Destroy(this.gameObject); }
/*Animation BreakDown * 0 - Standing Still * 1 - Running * 2 - Squatting * 3 - Reverse Squatting * 4 - Squatting Still * 5 - Squat Running */ void Awake() { controller = GetComponent <Controller> (); getDamage = GetComponent <GetDamage> (); allKnow = GameObject.Find("theOmniscient").GetComponent <GatherAllKnowledge> (); crouching = false; uncrouching = false; onMyKnees = false; Physics2D.IgnoreLayerCollision(8, 8); conAnchs = new Vector2[] { new Vector2(0.025f, 0.37f), new Vector2(0.025f, 0.315f), new Vector2(0.025f, 0.2605f), new Vector2(0.025f, 0.2055f), new Vector2(0.015f, 0.15f), }; if (GameObject.Find("CheckPoints")) { checkPoint = GameObject.Find("CheckPoints").GetComponent <CheckPoint>(); } char1 = false; char2 = false; teleHovering = false; copterHovering = false; recoRotoSpeed = 25f; angleTol = 3f; liftForce = 75f; jetSpeed = 300f; unitTimeFrame = .083f; platforms = new Collider2D[20]; minMoveRad = .4f; if (GameObject.Find("ZoomZone")) { zoomZone = GameObject.Find("ZoomZone").GetComponent <ZoomZone>(); } if (gameObject.name == "Hero1") { char1 = true; hud = GameObject.Find("HUD1").GetComponent <HUD> (); healthBar = GameObject.Find("HealthBar1").GetComponent <HealthBar> (); arm = GameObject.Find("Arm1"); shield = GameObject.Find("Shield1"); hammer = GameObject.Find("Hammer1"); tractorBeam = GameObject.Find("TractorBeam1"); weaponDetectorScript = GameObject.Find("WeaponDetector1").GetComponent <WeaponDetectorScript> (); chargeDisplay = GameObject.Find("ChargeBar1").GetComponent <ChargeDisplay> (); } else { char2 = true; hud = GameObject.Find("HUD2").GetComponent <HUD> (); healthBar = GameObject.Find("HealthBar2").GetComponent <HealthBar> (); arm = GameObject.Find("Arm2"); shield = GameObject.Find("Shield2"); hammer = GameObject.Find("Hammer2"); tractorBeam = GameObject.Find("TractorBeam2"); weaponDetectorScript = GameObject.Find("WeaponDetector2").GetComponent <WeaponDetectorScript> (); chargeDisplay = GameObject.Find("ChargeBar2").GetComponent <ChargeDisplay> (); } polyCols = GetComponents <PolygonCollider2D> (); cirCol = GetComponent <CircleCollider2D> (); hamCol = hammer.GetComponent <BoxCollider2D> (); shieldCol = shield.GetComponent <PolygonCollider2D> (); tractorBeamCol = tractorBeam.GetComponent <PolygonCollider2D> (); weaponCol = weaponDetectorScript.GetComponent <CircleCollider2D> (); spriteArm = arm.GetComponent <SpriteRenderer> (); spriteShield = shield.GetComponent <SpriteRenderer> (); spriteHero = GetComponent <SpriteRenderer> (); spriteHammer = hammer.GetComponent <SpriteRenderer> (); startingBounce = cirCol.sharedMaterial.bounciness; startingFriction = cirCol.sharedMaterial.friction; armRotateScript = arm.GetComponent <ArmRotate> (); armRot = arm.transform.rotation; armHinge = arm.GetComponent <HingeJoint2D>(); shieldHinge = shield.GetComponent <HingeJoint2D>(); hammerHinge = hammer.GetComponent <HingeJoint2D> (); alive = true; //transform.position = Vector3.zero; if (Application.loadedLevelName == "BattleArena") { spawnSpots = new Vector3[6]; spawnSpots[0] = new Vector3(0f, -2f, 0f); spawnSpots [1] = new Vector3(-2f, -1f, 0f); spawnSpots [2] = new Vector3(2f, -1f, 0f); spawnSpots [3] = new Vector3(0f, 0f, 0f); spawnSpots [4] = new Vector3(0f, -2f, 0f); spawnSpots [5] = new Vector3(0f, -2f, 0f); } else if (Application.loadedLevelName == "BattleShrine") { spawnSpots = new Vector3[6]; spawnSpots [0] = new Vector3(0f, 2.5f, 0f); spawnSpots [1] = new Vector3(-1f, 0f, 0f); spawnSpots [2] = new Vector3(1f, 0f, 0f); spawnSpots [3] = new Vector3(0f, -2.5f, 0f); spawnSpots [4] = new Vector3(-3.5f, -.75f, 0f); spawnSpots [5] = new Vector3(3.5f, -.75f, 0f); } else { spawnSpots = new Vector3[6]; spawnSpots [0] = new Vector3(0f, -2f, 0f); spawnSpots [1] = new Vector3(-2f, -1f, 0f); spawnSpots [2] = new Vector3(2f, -1f, 0f); spawnSpots [3] = new Vector3(0f, 0f, 0f); spawnSpots [4] = new Vector3(0f, -2f, 0f); spawnSpots [5] = new Vector3(0f, -2f, 0f); } wallJumpLagTime = .7f; runningVelThresh = .3f; runningCrouchVelThresh = .1f; wallDelay = false; heroAnimator = GetComponent <Animator>(); time2Respawn = 2f; startingHealth = 100; fallTimeDelay = 1f; runningSpeed = 7.5f; floatingSpeed = runningSpeed; jumpSpeed = 200f; fallSpeed = -50f; maxVelocity = new Vector2(2f, 5f); maxFloatVelocity = new Vector2(2.5f, 2.5f); floorDetectionBoxHeights = new Vector2(0.023f, 0.2f); forceX = 0; forceY = 0; i = 0; damage = 0; startingJumpSpeed = jumpSpeed; startingRunningSpeed = runningSpeed; startingFallSpeed = fallSpeed; startingMaxVelocity = maxVelocity.x; followP1 = true; }