public void SetTarget(GameObject t) //also starts the tractor beam moving { target = t; targetRT = (RectTransform)t.transform; targetShield = t.GetComponent <Enemy>().GetShield(); initialHP = targetShield.GetCurrentHP(); radians = Mathf.Atan2(targetRT.anchoredPosition.y - bossRT.anchoredPosition.y, targetRT.anchoredPosition.x - bossRT.anchoredPosition.x); //what angle's it at? transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, Rotations.RadiansCounterclockwiseFromXAxisToEulerAngles(radians) - bulk.transform.eulerAngles.z); //match angle distance = Mathf.Sqrt((targetRT.anchoredPosition.x - bossRT.anchoredPosition.x) * (targetRT.anchoredPosition.x - bossRT.anchoredPosition.x) + (targetRT.anchoredPosition.y - bossRT.anchoredPosition.y) * (targetRT.anchoredPosition.y - bossRT.anchoredPosition.y)); float zoneDist = distance - headMinimum; //how far is it from the hidden head of the beam, not the center of the dial? fastLegDist = FAST_LEG * zoneDist; mediLegDist = MEDI_LEG * zoneDist; slowLegDist = SLOW_LEG * zoneDist; float bonusTimeMultiplier = 0; //replace with actual calculation later, between 0 and 1 based on distance reachTime = MIN_REACH_TIME + (bonusTimeMultiplier * MAX_BONUS_TIME); //set how long it's going to take to reach the drop state = states.REACHING; grabTimer = new Timer(); }
public void SetTarget(GameObject t) { //also starts the tractor beam moving target = t; targetRT = (RectTransform)t.transform; targetShield = t.GetComponent<Enemy>().GetShield(); initialHP = targetShield.GetCurrentHP(); radians = Mathf.Atan2(targetRT.anchoredPosition.y-bossRT.anchoredPosition.y,targetRT.anchoredPosition.x-bossRT.anchoredPosition.x); //what angle's it at? transform.eulerAngles = new Vector3(transform.eulerAngles.x,transform.eulerAngles.y, Rotations.RadiansCounterclockwiseFromXAxisToEulerAngles(radians)-bulk.transform.eulerAngles.z); //match angle distance = Mathf.Sqrt((targetRT.anchoredPosition.x-bossRT.anchoredPosition.x)*(targetRT.anchoredPosition.x-bossRT.anchoredPosition.x) + (targetRT.anchoredPosition.y-bossRT.anchoredPosition.y)*(targetRT.anchoredPosition.y-bossRT.anchoredPosition.y)); float zoneDist = distance - headMinimum; //how far is it from the hidden head of the beam, not the center of the dial? fastLegDist = FAST_LEG*zoneDist; mediLegDist = MEDI_LEG*zoneDist; slowLegDist = SLOW_LEG*zoneDist; float bonusTimeMultiplier = 0; //replace with actual calculation later, between 0 and 1 based on distance reachTime = MIN_REACH_TIME + (bonusTimeMultiplier*MAX_BONUS_TIME); //set how long it's going to take to reach the drop state = states.REACHING; grabTimer = new Timer(); }
public void Update() { if (state == states.REACHING) { float progress = grabTimer.TimeElapsedSecs() / reachTime; float dist; if (progress >= 1f) //if we've reached past { state = states.GRABBING; dist = distance; grabTimer.Restart(); } else if (progress > SLOW_THRESH) { float subProgress = (progress - SLOW_THRESH) / (1f - SLOW_THRESH); dist = headMinimum + fastLegDist + mediLegDist + subProgress * slowLegDist; } else if (progress > MEDI_THRESH) { float subProgress = (progress - MEDI_THRESH) / (SLOW_THRESH - MEDI_THRESH); //how much of the medium speed leg has it travered? dist = headMinimum + fastLegDist + subProgress * mediLegDist; //get actual distance } else { float subProgress = progress / MEDI_THRESH; //how much of the fast leg has it traversed? dist = headMinimum + subProgress * fastLegDist; //get actual distance from center to put the thing } if (progress >= 1f) { PositionHead(); } else { PositionHead(dist); } } else if (state == states.GRABBING) { drainTimer.Restart(); state = states.DRAINING; } else if (state == states.DRAINING) { float drainProg = drainTimer.TimeElapsedSecs() / drainTime; if (targetShield != null) { float targetHP = initialHP - (initialHP * drainProg); float currentHP = targetShield.GetCurrentHP(); float drainedAmount = targetShield.Drain(currentHP - targetHP); bulk.ReceiveDrainedShields(drainedAmount); } PositionHead(); if (drainTimer.TimeElapsedSecs() > drainTime) { targetShield.Drain(targetShield.GetBaseHP()); //drain any remaining shield state = states.FADING; } } else if (state == states.FADING) { float progress = 1f - (grabTimer.TimeElapsedSecs() / reachTime); headImg.color = new Color(headImg.color.r, headImg.color.g, headImg.color.b, progress); beamImg.color = new Color(beamImg.color.r, beamImg.color.g, beamImg.color.b, progress); float dist = headMinimum + fastLegDist + mediLegDist + slowLegDist; PositionHead(dist); if (progress < 0) { target.GetComponent <Enemy>().UndoBulkDrainTarget(); state = states.DONE; } } else if (state == states.DONE) { Destroy(gameObject); } }