private void updateTransition() { visibilityCurrent = Mathf.Clamp01(visibilityCurrent + Time.deltaTime / transitionTime); float t = visibilityCurrent; if (easeIn) { if (easeOut) { t = BenjasMath.easeInOut(t); } else { t = BenjasMath.easeIn(t); } } else if (easeOut) { t = BenjasMath.easeOut(t); } //t goes automaticly backwards when going out trafo.anchoredPosition3D = Vector3.Lerp(transitionVisisbiltyTarget.position, idle.position, t); trafo.localScale = Vector3.Lerp(transitionVisisbiltyTarget.scale, idle.scale, t); setAlpa(Mathf.Lerp(transitionVisisbiltyTarget.alpha, idle.alpha, t)); if (visibilityCurrent == visibilityTarget) { killTransition(); } }
// Update is called once per frame void Update() { if (Transforms.Length > 1) { if (BenjasMath.countdownToZero(ref timeToNext)) { factor = (float)animationTime * (1 + Mathf.Lerp(-aniTimeVariation, aniTimeVariation, Random.value)); timeToNext = factor; origin = target; target++; } if (target >= Transforms.Length) { target = 0; } float t; t = BenjasMath.easeInOut(1f - timeToNext / factor); transform.position = Vector3.Lerp(Transforms[origin].position, Transforms[target].position, t); t = BenjasMath.easeInOut(1f - rotationSpeedup * timeToNext / factor); transform.eulerAngles = BenjasMath.angularLerp(Transforms[origin].eulerAngles, Transforms[target].eulerAngles, t); } else { this.enabled = false; } }
//BUG BUG BUG !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //only update compass after level have been loaded, ner during load public void setCompass(float Angle) { Vector3 pos = compassStrip.anchoredPosition3D; latitudeCompass = BenjasMath.keepAngle0to360(Angle); xposCompass = BenjasMath.map(latitudeCompass, 0, 360, xPosAtZero, xPosAt360, false); pos.x = xposCompass; compassStrip.anchoredPosition3D = pos; }
public void advanced() { Mathf.Clamp01(compensateYaw); Mathf.Clamp01(dampenYawCompensation); if (cam != null) { Vector3 eul = new Vector3(); eul.x = Mathf.Lerp(eul.x, -compensateYaw * BenjasMath.keepAngleBetween(transform.localEulerAngles.x, -180, 180), dampenYawCompensation); cam.transform.localEulerAngles = eul; } }
public void setBacon(float Angle) { Vector3 pos = baconOne.anchoredPosition3D; angleBacon = BenjasMath.keepAngleBetween(Angle, -180, 180); xposBacon = BenjasMath.map(angleBacon, -clampBaconAngleAt, clampBaconAngleAt, -clampBaconAt, clampBaconAt, true); //center around 0 degrees pos.x = xposBacon; baconOne.anchoredPosition3D = pos; }
private Vector3 getHandAngle(float value, float min, float max, float minAngle, float maxAngle, float currentAngle) { float targetAngle = BenjasMath.map(value, min, max, minAngle, maxAngle); if (instrumentMaxDegreesPerSec > 0) { targetAngle = Mathf.MoveTowardsAngle(currentAngle, targetAngle, instrumentMaxDegreesPerSec * Time.deltaTime); } return(new Vector3(0, 0, targetAngle)); }
// Update is called once per frame void Update() { if (testFog) { doFog(); } if (isFogging) { if (BenjasMath.countdownToZero(ref fogTime)) { isFogging = false; } setAlpha(20 * timeFunktion(fogTime / maxFogTime)); } }
public int distribute(int maxAppearances) { if (!this.spawnsSearched) { findSpawns(); } maxCount = maxAppearances; Debug.Log(name + " generating random indices"); BenjasMath.randomizeArray(spawns); for (int i = 0; i < spawns.Length; i++) { spawns[i].SetActive((i < maxAppearances)); } return(maxAppearances); }
public void updatespeedo() { if (glider != null) { sppedoSmoothing = Mathf.Clamp(sppedoSmoothing, 0, 0.999999f); if (ignoreVerticalSpeed) { speedoValue = Mathf.Lerp(glider.speedHorrizontal, speedoValue, sppedoSmoothing); } else { speedoValue = Mathf.Lerp(glider.speed, speedoValue, sppedoSmoothing); } speedoHand.localEulerAngles = getHandAngle(speedoValue, speedoMin, speedoMax, speedoMinAngle, speedoMaxAngle, speedoHand.localEulerAngles.z); speedDigits.text = Mathf.FloorToInt(speedoValue).ToString() + " " + speedUnit; //adaptive smoothing depending on height altChangeSmoothingMinMax.x = Mathf.Clamp(altChangeSmoothingMinMax.x, 0, 0.999999f); altChangeSmoothingMinMax.y = Mathf.Clamp(altChangeSmoothingMinMax.y, 0, 0.999999f); altChangeSmoothing = BenjasMath.map(altitudeValue , altChangeSmoothingAltLimits.x, altChangeSmoothingAltLimits.y , altChangeSmoothingMinMax.x, altChangeSmoothingMinMax.y); //apply values altitudeValue = Mathf.Lerp(glider.altitude, altitudeValue, altChangeSmoothing); altChangeValue = Mathf.Lerp(glider.altChange, altChangeValue, altChangeSmoothing); altChangeHand.localEulerAngles = getHandAngle(altChangeValue, altChangeMin, altChangeMax, altChangeMinAngle, altChangeMaxAngle, altChangeHand.localEulerAngles.z); int alt = Mathf.FloorToInt(altitudeValue); string altsring = alt.ToString(); altDigitsRed.text = altsring; altDigitsBlack.text = altsring; if (alt < 10) { altsring = "0" + altsring; } if (alt < 100) { altsring = "0" + altsring; } //if (alt < 1000) altsring = "0" + altsring; altDigitsWhite.text = altsring; altDigitsUnit.text = altUnit; } }
private void updateMap(Vector3 coordinates) { positionMap = mapPointer.anchoredPosition3D; positionWorld = coordinates; //Debug.Log("map" +positionMap.x); positionMap.x = BenjasMath.map(positionWorld.x, SWworld.x, NEworld.x, mapMinScaled.x, mapMaxScaled.x, clampMin.x, clampMax.x); //Debug.Log(positionMap.x); positionMap.y = BenjasMath.map(positionWorld.z, SWworld.z, NEworld.z, mapMinScaled.y, mapMaxScaled.y, clampMin.y, clampMax.y); mapPointer.anchoredPosition3D = positionMap; }
void interceptRectangular(Transform vessel, float maxVelo, float maxAcc) { if (maxVelo != 0 && maxAcc != 0) { //calculate direction from this object into forward path of glider Vector3 direction = Vector3.Cross(vessel.forward, vessel.position - transform.position); direction = Vector3.Cross(direction, vessel.forward); //calculate point of rendevous (intersection of flightpaths) Vector3 rendevous = BenjasMath.ClosestPointToIntersect(vessel.position, vessel.forward, transform.position, direction); //has player passed the point of a 90° intercept course? Vector3 rendevousVessel = rendevous - vessel.position; bool passed = Vector3.Dot(rendevousVessel, vessel.forward) < 0; if (!passed) { Debug.DrawLine(transform.position, rendevous, debugColor); Debug.DrawLine(vessel.position, rendevous); // where do we need to fly direction = (rendevous - transform.position); // Timing // velocity player float velo = player.GetComponent <Rigidbody>().velocity.magnitude; // estimated Time of arrival of player float timeVessel = rendevousVessel.magnitude / Mathf.Max(velo, 0.000001f); // estimated Time of arrival of this float time = direction.magnitude / Mathf.Max(rigi.velocity.magnitude, 0.000001f); //use direction for acceleration direction = direction.normalized * maxAcc; //acc forward or backward direction *= (time > timeVessel)?1:-1; //softly restrict speed to 'maximumVelocity' direction *= (1 - rigi.velocity.magnitude / maxVelo); //apply acceleration rigi.AddForce(direction, ForceMode.Acceleration); speed = rigi.velocity.magnitude; } } // }
void Update() { if (stopEveryFrame) { Debug.Break(); } cheatkeys(); if (state == STATE.PLAYING) { float normalizedGametime = BenjasMath.timer(ref gameTime, maxGameTime, pausing); updateHUD(normalizedGametime); if (normalizedGametime == 1) { onTimeout(); } if (!pausing) { if (spawnByTime && BenjasMath.countdownToZero(ref timeToSpawn)) { // switch off spawning by time after first object and switch on spawning when hitting a collider spawnByTime = false; spawnByCollider = true; //spawn first object onSpawn(); } if (levelControl.isLastLevel()) { if (Vector3.Distance(glider.transform.position, levelControl.levelInfo().finish.transform.position) < distanceFinishNear) { onFinalFinishNear(); } } } } else if (state == STATE.ATSTART) { updateHUD(); } }
void doDocking() { float t = Mathf.Pow(Mathf.InverseLerp(dockingDuration, 0, dockingTime), 1); // float t2 = Mathf.Clamp01(Mathf.InverseLerp(dockingDuration,dockingDuration-1,dockingTime)); //lerp the position transform.position = Vector3.Lerp(transform.position, nextDockingPoint.position, t); //lerp the rotation transform.eulerAngles = BenjasMath.angularLerp(transform.eulerAngles, nextDockingPoint.eulerAngles, t); // lerp the velocity //rigi.velocity = Vector3.Lerp(rigi.velocity , Vector3.zero, t2); float dist = Vector3.Distance(transform.position, nextDockingPoint.position); float angularDist = Vector3.Distance(transform.eulerAngles, nextDockingPoint.eulerAngles); //test if docking time is over or position is close enough (10mm and 1/10°) if (BenjasMath.countdownToZero(ref dockingTime) || (dist < 0.01 && angularDist < 0.1)) { finishDocking(); } }
private bool runDelay() { return(BenjasMath.countdownToZero(ref delay)); }