private void WiggleLegs() { float degrees = 45; float speed = 10; Vector3 inputDirLocal = transform.InverseTransformDirection(inputDirection); Vector3 axis = Vector3.Cross(inputDirLocal, Vector3.up); // check alignment of inputDirLocal against forward vector float alignment = Vector3.Dot(inputDirLocal, Vector3.forward); //Vector3.forward == new Vector3(0,0,1) alignment = Mathf.Abs(alignment); // flips negative numbers degrees *= AnimMath.Lerp(0.25f, 1, alignment); float wave = Mathf.Sin(Time.time * speed) * degrees; leg1.localRotation = AnimMath.Slide(leg1.localRotation, Quaternion.AngleAxis(wave, axis), .001f); leg2.localRotation = AnimMath.Slide(leg2.localRotation, Quaternion.AngleAxis(-wave, axis), .001f); }
private void WiggleLegs() { float degrees = 45; float speed = 10; if (isTryingToMove) { Vector3 localDirection = transform.InverseTransformDirection(inputDirection); Vector3 axis = Vector3.Cross(localDirection, Vector3.up); //check localDirection against forward vector float alignment = Vector3.Dot(localDirection, Vector3.forward); //if (alignment < 0) alignment *= -1; // flip negative numbers alignment = Mathf.Abs(alignment); // flip negative numbers degrees *= AnimMath.Lerp(0.25f, 1, alignment); //decrease degree variable when strafing float wave = Mathf.Sin(Time.time * speed) * degrees; // (-45 to 45) leg1.localRotation = AnimMath.Slide(leg1.localRotation, Quaternion.AngleAxis(wave, axis), 0.01f); leg2.localRotation = AnimMath.Slide(leg2.localRotation, Quaternion.AngleAxis(-wave, axis), 0.01f); } else { leg1.localRotation = AnimMath.Slide(leg1.localRotation, Quaternion.identity, 0.01f); leg2.localRotation = AnimMath.Slide(leg2.localRotation, Quaternion.identity, 0.01f); } }
private void WiggleLegs() { float degrees = 45; float speed = 10; bool wantsToRun = Input.GetKey(KeyCode.LeftShift); if (wantsToRun) { speed = speed * 2.5f; // if running, increase run animation speed by 2.5x } Vector3 inputDirLocal = transform.InverseTransformDirection(inputDirection); Vector3 axis = Vector3.Cross(inputDirLocal, Vector3.up); // check the alignment of inputDirLocal against forward vector float alignment = Vector3.Dot(inputDirLocal, Vector3.forward); //if (alignment < 0) alignment *= -1; // flips negative numbers // ^^^ Both do same thing, choose one vvv // alignment = Mathf.Abs(alignment); // flips negative numbers degrees *= AnimMath.Lerp(.25f, 1, alignment); // decrease "degrees" variable when strafing float wave = Mathf.Sin(Time.time * speed) * degrees; leg1.localRotation = AnimMath.Slide(leg1.localRotation, Quaternion.AngleAxis(wave, axis), .001f); leg2.localRotation = AnimMath.Slide(leg2.localRotation, Quaternion.AngleAxis(-wave, axis), .001f); //leg1.localRotation = Quaternion.Euler(wave, 0, 0); //This code is now updated to allow leg rotation when turning ^^^ //leg2.localRotation = Quaternion.Euler(-wave, 0, 0); }
protected override void UpdateFrameInternal() { if (ActionTime < AnimRushTime) { //dont do anything; the animation itself will take care of pull-back MapLoc = FromLoc * GraphicsManager.TileSize; } else if (ActionTime < AnimHitTime) { double intb = (double)(ActionTime - AnimRushTime).FractionOf(AnimHitTime - AnimRushTime); Loc newLoc = new Loc(AnimMath.Lerp(FromLoc.X * GraphicsManager.TileSize, ToLoc.X * GraphicsManager.TileSize, intb), AnimMath.Lerp(FromLoc.Y * GraphicsManager.TileSize, ToLoc.Y * GraphicsManager.TileSize, intb)); MapLoc = newLoc; } else if (ActionTime < AnimReturnTime) { Loc newLoc = ToLoc * GraphicsManager.TileSize; MapLoc = newLoc; } else if (ActionTime < AnimTotalTime) { double intb = (double)(ActionTime - AnimReturnTime).FractionOf(AnimTotalTime - AnimReturnTime); Loc newLoc = new Loc(AnimMath.Lerp(ToLoc.X * GraphicsManager.TileSize, RecoilLoc.X * GraphicsManager.TileSize, intb), AnimMath.Lerp(ToLoc.Y * GraphicsManager.TileSize, RecoilLoc.Y * GraphicsManager.TileSize, intb)); MapLoc = newLoc; } else { MapLoc = RecoilLoc * GraphicsManager.TileSize; } }
/// <summary> /// This function animates the player's legs. /// </summary> private void WiggleLegs() { float degrees = 45; float speed = 10; // Get the vector perpendicular to the input direction. Vector3 inputDirectionLocal = transform.InverseTransformDirection(inputDirection); Vector3 axis = Vector3.Cross(inputDirectionLocal, Vector3.up); // Check the alignment of inputDirLocal against forward vector float alignment = Vector3.Dot(inputDirectionLocal, Vector3.forward); //if (alignment < 0) alignment *= -1; // flips the nmumber alignment = Mathf.Abs(alignment); // flips negative numbers /* * 1 = lots of movement * 0 = no movement * -1 = lots of movement */ // Remap alignment from .25 to 1, and multiply it by degrees. degrees *= AnimMath.Lerp(0.25f, 1, alignment); // Set the local rotation of the legs as the player moves. float wave = Mathf.Sin(Time.time * speed) * degrees; leg1.localRotation = AnimMath.Slide(leg1.localRotation, Quaternion.AngleAxis(wave, axis), .001f); leg2.localRotation = AnimMath.Slide(leg2.localRotation, Quaternion.AngleAxis(-wave, axis), .001f); }
protected override void UpdateFrameInternal() { MapLoc = AnimLoc * GraphicsManager.TileSize; int farthest_distance = GraphicsManager.TileSize * (FallShort ? 1 : 2) / 3; Loc toOffset = CharDir.GetLoc() * farthest_distance; if (ActionTime < AnimRushTime) { //dont do anything; the animation itself will take care of pull-back } else if (ActionTime < AnimHitTime) { double intb = (double)(ActionTime - AnimRushTime).FractionOf(AnimHitTime - AnimRushTime); Loc newLoc = new Loc(AnimMath.Lerp(0, toOffset.X, intb), AnimMath.Lerp(0, toOffset.Y, intb)); drawOffset = newLoc; } else if (ActionTime < AnimReturnTime) { drawOffset = toOffset; } else { double intb = (double)(ActionTime - AnimReturnTime).FractionOf(AnimTotalTime - AnimReturnTime); Loc newLoc = new Loc(AnimMath.Lerp(toOffset.X, 0, intb), AnimMath.Lerp(toOffset.Y, 0, intb)); drawOffset = newLoc; } }
// Update is called once per frame void Update() { if (!pause) { //lerpPercent += planetSpeed * Time.deltaTime; } //this float radius is lerping from interpA to interpB using a time value inherited from BehaviorProperties //float radius = AnimMath.Lerp(interpA, interpB, BehaviorProperties.Instance.GlobalTime()); float radius = AnimMath.Lerp(interpA, interpB, InterpTime()); //We call the FindOrbitPoint method and pass in: //Our radius which is the point along the path we want to be right now //Our magX which is a random value that adjusts what the path looks like //Our magY which is a random value that adjusts what the path looks like //Since both those values are variables I don't think we need to pass them in Vector3 pos = FindOrbitPoint(radius); //We set the Vector3 pos we get above to our transform position transform.position = pos; transform.Rotate(Time.deltaTime * rotationSpeed, Time.deltaTime * rotationSpeed, Time.deltaTime * rotationSpeed); //We update the points in the path UpdatePoints(); }//End of Update method
public IEnumerator <YieldInstruction> MoveCamera(Loc loc, int time, bool toPlayer) { Loc startLoc = ZoneManager.Instance.CurrentGround.ViewCenter.HasValue ? ZoneManager.Instance.CurrentGround.ViewCenter.Value : FocusedCharacter.Bounds.Center + ZoneManager.Instance.CurrentGround.ViewOffset; Loc endLoc = loc; if (toPlayer) { startLoc -= FocusedCharacter.Bounds.Center; endLoc -= FocusedCharacter.Bounds.Center; ZoneManager.Instance.CurrentGround.ViewCenter = null; } else { ZoneManager.Instance.CurrentGround.ViewOffset = Loc.Zero; } int currentFadeTime = time; while (currentFadeTime > 0) { currentFadeTime--; if (toPlayer) { ZoneManager.Instance.CurrentGround.ViewOffset = new Loc(AnimMath.Lerp(loc.X, startLoc.X, (double)currentFadeTime / time), AnimMath.Lerp(loc.Y, startLoc.Y, (double)currentFadeTime / time)); } else { ZoneManager.Instance.CurrentGround.ViewCenter = new Loc(AnimMath.Lerp(loc.X, startLoc.X, (double)currentFadeTime / time), AnimMath.Lerp(loc.Y, startLoc.Y, (double)currentFadeTime / time)); } yield return(new WaitForFrames(1)); } }
public void DoTheLerp(float p) { transform.position = AnimMath.Lerp( objectStart.transform.position, objectEnd.transform.position, p); }
private void LerpButtons(GameObject buttonToMove) { if (!moveButtonBack) { for (int i = 0; i < 100; i++) { if (i != 0) { i = i / 100; Vector3 posMover = AnimMath.Lerp(posA.transform.position, posB.transform.position, i); buttonToMove.gameObject.transform.position += new Vector3(0, posMover.y, 0); } } moveButtonBack = true; } else { for (int i = 100; i > 0; i--) { if (i != 0) { i = i / 100; Vector3 posMover = AnimMath.Lerp(posA.transform.position, posB.transform.position, i); buttonToMove.gameObject.transform.position += new Vector3(0, posMover.y, 0); } } moveButtonBack = false; } }
/// <summary> /// Legs move around when the player moves to give the look that the player has a walk animation /// </summary> private void WiggleLegs() { float degrees = 45; // Degrees the legs would move to float speed = 10; // How has the legs are moving // Chancing the inputDirection direction from world space to local space Vector3 inputDirLocal = transform.InverseTransformDirection(inputDirection); Vector3 axis = Vector3.Cross(inputDirLocal, Vector3.up); // check the alignment of inputDirLocal againts forward vector float alignment = Vector3.Dot(inputDirLocal, Vector3.forward); //if (alignment < 0) alignment *= -1; // flips negatve numbers alignment = Mathf.Abs(alignment); // flips negative numbers // 1 = yes! // 0 = no! // -1 = yes! degrees *= AnimMath.Lerp(.25f, 1, alignment); // decrease 'degrees' when strafing float wave = Mathf.Sin(Time.time * speed) * degrees; // output values between... // Plays the animation using the slide function from AnimMath to give a sense of easing leg1.localRotation = AnimMath.Slide(leg1.localRotation, Quaternion.AngleAxis(wave, axis), .001f); leg2.localRotation = AnimMath.Slide(leg2.localRotation, Quaternion.AngleAxis(-wave, axis), .001f); }
private void doDeathAnimation() { //do Player Death anims if (isPlayer) { Vector3 targetScale = transform.localScale - scaleChange; transform.localScale = AnimMath.Lerp(transform.localScale, targetScale, .01f); if (rotateRightOnDeath) { transform.Rotate(0, 360 * Time.deltaTime, 0); } if (!rotateRightOnDeath) { transform.Rotate(0, -360 * Time.deltaTime, 0); } } //do turret death anims else if (!isPlayer) { Vector3 targetScale = transform.localScale - scaleChange; transform.localScale = AnimMath.Lerp(transform.localScale, targetScale, .01f); if (rotateRightOnDeath) { transform.Rotate(0, 360 * Time.deltaTime, 0); } if (!rotateRightOnDeath) { transform.Rotate(0, -360 * Time.deltaTime, 0); } } }
private void wiggleLegs() { float degrees = 45; float speed = 10; Vector3 inputDirLocal = transform.InverseTransformDirection(inputDirection); Vector3 axis = Vector3.Cross(inputDirLocal, Vector3.up); // check the alignment of inputDirLocal against forward vector float alignment = Vector3.Dot(inputDirLocal, Vector3.forward); alignment = Mathf.Abs(alignment); degrees *= AnimMath.Lerp(.25f, 1, alignment); //decrease 'degrees' when strafing float wave = Mathf.Sin(Time.time * speed) * degrees; leg1.localRotation = AnimMath.Slide(leg1.localRotation, Quaternion.AngleAxis(wave, axis), .001f); leg2.localRotation = AnimMath.Slide(leg2.localRotation, Quaternion.AngleAxis(-wave, axis), .001f); if (isShiftHeld) { //IMPLEMENT ARM SWING CODE } }
private void DoTheLerp(float p) { transform.position = AnimMath.Lerp( startObject.transform.position, endObject.transform.position, p ); }
private Vector3 CalcPositionOnCurve(float percent) { Vector3 c = AnimMath.Lerp(positionA.position, handle.position, percent); Vector3 d = AnimMath.Lerp(handle.position, positionB.position, percent); Vector3 f = AnimMath.Lerp(c, d, percent); return(f); }
/// <summary> /// Uses lerp to /// </summary> private void SwivelPosition() { //if (a == null || b == null) return; //These are float values by definition they will have a value float p = curve.Evaluate(percent); float targetValue = AnimMath.Lerp(a, b, p); xAngle = AnimMath.Dampen(0, targetValue, .5f); }
private Vector3 CalcPositionOnCurve(float percent) { Vector3 c = AnimMath.Lerp(positionA.position, handleA.position, percent); Vector3 d = AnimMath.Lerp(handleB.position, positionB.position, percent); Vector3 e = AnimMath.Lerp(handleA.position, handleB.position, percent); Vector3 f = AnimMath.Lerp(c, e, percent); Vector3 g = AnimMath.Lerp(e, d, percent); return(AnimMath.Lerp(f, g, percent)); }
private void CalcPosition() { if (pos1 == null || pos2 == null) { return; } currentEaseTarget = AnimMath.Lerp(pos1.position, planetToFollow.transform.position, percent); transform.position = AnimMath.Dampen(transform.position, currentEaseTarget, .5f); }
private Vector3 CalcPositionOnCurve(float percent) { // posC = lerp between posA and handle Vector3 posC = AnimMath.Lerp(posA.position, handle.position, percent); // posD = lerp between handle and posB Vector3 posD = AnimMath.Lerp(handle.position, posB.position, percent); // posF = lerp between posC and posD Vector3 posF = AnimMath.Lerp(posC, posD, percent); return(posF); }
private Vector3 CalcPositionOnCurve(float percent) { // pC = lerp between pA and handle Vector3 c = AnimMath.Lerp(pointA.position, handle.position, percent); Vector3 d = AnimMath.Lerp(handle.position, pointB.position, percent); Vector3 f = AnimMath.Lerp(c, d, percent); return(f); }
Vector3 CalcPosition() { if (pozA == null || pozB == null) { return(Vector3.zero); } p = LittleTime / BigTime; float tp = DaddysBigCurve.Evaluate(p); /*transform.position*/ return(AnimMath.Lerp(pozA.position, pozB.position, tp)); }
private Vector3 CalcPositionOnCurve(float percent) { // position c = lerp between position a and handle Vector3 c = AnimMath.Lerp(pointA.position, handleA.position, percent); Vector3 d = AnimMath.Lerp(handleB.position, pointB.position, percent); Vector3 e = AnimMath.Lerp(handleA.position, handleB.position, percent); Vector3 f = AnimMath.Lerp(c, e, percent); Vector3 g = AnimMath.Lerp(e, d, percent); return(AnimMath.Lerp(f, g, percent)); }
private Vector3 CalcPositionOnCurve(float percent) { // pC = lerp between pA and handle Vector3 positionC = AnimMath.Lerp(positionA.position, handle.position, percent); // pD = lerp between handle and pB Vector3 positionD = AnimMath.Lerp(handle.position, positionB.position, percent); // pF = lerp between pC and pD Vector3 positionF = AnimMath.Lerp(positionC, positionD, percent); return(positionF); }
// Update is called once per frame void Update() { if (target == null) { return; } Vector3 look = target.position - transform.position; look.Normalize(); Quaternion targetRotation = Quaternion.LookRotation(look, Vector3.up); transform.rotation = AnimMath.Lerp(transform.rotation, targetRotation, .01f); }
public void CalcPosition() { if (currentTransform == null || planetTransform == null) { return; } float p = curve.Evaluate(percent); currentEaseTarget = AnimMath.Lerp(currentTransform.position, planetTransform.transform.position, p); transform.position = AnimMath.Dampen(transform.position, currentEaseTarget - offset, .1f); }
public Vector3 FindPositionAt(float p) { if (worldPoints == null) { return(Vector3.zero); } if (worldPoints.Length == 0) { return(Vector3.zero); } if (worldPoints.Length == 1) { return(points[0]); } if (worldPoints.Length == 2) { return(AnimMath.Lerp(worldPoints[0], worldPoints[1], p)); } Vector3 result = Vector3.zero; float leftValue = 0; //this is how far we have walked down the line for (int i = 0; i < curveLengths.Length; i++) { float rightValue = leftValue + curveLengths[i]; float rightPercent = rightValue / splineLength; if (rightPercent >= p) { float leftPercent = leftValue / splineLength; float curvePercent = (p - leftPercent) / (rightPercent - leftPercent); Vector3 a = worldPoints[i]; Vector3 b = worldPoints[i + 1]; Vector3 c = worldPoints[i + 2]; if (i > 0) { a = AnimMath.Lerp(a, b, .5f); } if (i < curveLengths.Length - 1) { c = AnimMath.Lerp(b, c, .5f); } result = AnimMath.QuadraticBezier(a, b, c, curvePercent); break; } leftValue = rightValue; } return(result); }
// Update is called once per frame void Update() { float radius = AnimMath.Lerp(interpolatePointA, interpolatePointB, percentage); //We pass in time.time to make the planet move over time //We pass in magnitude to adjust how far around the planet the orbit is //So instead of time we can use Vector3 pos = FindOrbitPoint(radius, magnitude); //This returns a vector 3 we want to use for our transform.position transform.position = pos; //we set this vector 3 equal to our position to move the planet around //We update the points along the line renderer UpdatePoints(); }
protected override void UpdateFrameInternal() { FrameTick trueTime = ActionTime * SpeedMult; int curSegment = Math.Min(trueTime.ToFrames() / FINISH_TIME, MidLocs.Count - 1); Dir8 midDir = MidDirs[curSegment]; Loc fromLoc = MidLocs[curSegment]; Loc toLoc = curSegment + 1 < MidLocs.Count ? MidLocs[curSegment + 1] : ToLoc; dirOffset = (Dir8)(((int)midDir - (int)CharDir + DirExt.DIR8_COUNT) % DirExt.DIR8_COUNT); FrameTick segmentTime = trueTime - FINISH_TIME * curSegment; double intb = Math.Min(1.0, (double)segmentTime.FractionOf(FINISH_TIME)); MapLoc = new Loc(AnimMath.Lerp(fromLoc.X * GraphicsManager.TileSize, toLoc.X * GraphicsManager.TileSize, intb), AnimMath.Lerp(fromLoc.Y * GraphicsManager.TileSize, toLoc.Y * GraphicsManager.TileSize, intb)); }
void DrawSpline() { int numofCurves = points.Length - 2; for(int i =1; i <= numofCurves; i++) { Vector3 a = points[i - 1]; Vector3 b = points[i]; Vector3 c = points[i + 1]; if (i > 1) a = AnimMath.Lerp(a, b, .5f); if (i < numofCurves) c = AnimMath.Lerp(b, c, .5f); DrawCurve(a, b, c); } }
private Vector3 CalcPositionOnCurve(float percent) { // posC = lerp between posA and handleB Vector3 posC = AnimMath.Lerp(posA.position, handleA.position, percent); // posD = lerp between handleB and posB Vector3 posD = AnimMath.Lerp(handleB.position, posB.position, percent); // posE = lerp between the two handles Vector3 posE = AnimMath.Lerp(handleA.position, handleB.position, percent); // posF = lerp between posC and posD Vector3 posF = AnimMath.Lerp(posC, posE, percent); // posG = lerp between posE and posD Vector3 posG = AnimMath.Lerp(posE, posD, percent); // Final output is lerp between posF and posG return(AnimMath.Lerp(posF, posG, percent)); }