void Update() { // Use right click to drag the camera if (Input.GetButton("Fire2")) { // Change the pitch float mouseY = Input.GetAxis("Mouse Y"); float mouseX = Input.GetAxis("Mouse X"); targetPitch += mouseY * mouseSensitivityY; // Move the target to mouse targetYaw += mouseX * mouseSensitivityX; } float scroll = Input.GetAxisRaw("Mouse ScrollWheel"); targetDollyDis += scroll * mouseScrollMultiplier; targetDollyDis = Mathf.Clamp(targetDollyDis, 3.5f, 20); dollyDis = AnimMath.Slide(dollyDis, targetDollyDis, .05f); cam.transform.localPosition = new Vector3(0, 0, -dollyDis); // Clamp the pitch degrees //Quaternion targetRotation = Quaternion.Euler(pitch, yaw, 0); //transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, 0.01f); targetPitch = Mathf.Clamp(targetPitch, -89, 89); pitch = AnimMath.Slide(pitch, targetPitch, .05f); // Ease from current to target yaw = AnimMath.Slide(yaw, targetYaw, .05f); transform.rotation = Quaternion.Euler(pitch, yaw, 0); }
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; } }
// Update is called once per frame void Update() { if (Input.GetButton("Fire1")) { float mouseX = Input.GetAxis("Mouse X"); float mouseY = Input.GetAxis("Mouse Y"); targetYaw += mouseX * mouseSensitivityX; targetPitch += mouseY * mouseSensitivityY; } float scroll = Input.GetAxisRaw("Mouse ScrollWheel"); targetDollyDis += scroll * mouseScrollMultiplier; targetDollyDis = Mathf.Clamp(targetDollyDis, 2.5f, 15f); dollyDis = AnimMath.Slide(dollyDis, targetDollyDis, .05f); //Ease cam.transform.localPosition = new Vector3(0, 0, -dollyDis); targetPitch = Mathf.Clamp(targetPitch, -89, 89); pitch = AnimMath.Slide(pitch, targetPitch, .05f); //Ease yaw = AnimMath.Slide(yaw, targetYaw, .05f); //Ease transform.rotation = Quaternion.Euler(pitch, 0, 0); }
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)); } }
// Update is called once per frame void Update() { lookAtPlanet(); transform.position = AnimMath.Slide(transform.position, target, .05f); if (Input.GetButton("Fire1")) { float mouseY = Input.GetAxis("Mouse Y"); float mouseX = Input.GetAxis("Mouse X"); pitch -= mouseY * mouseSensitivityY; yaw += mouseX * mouseSensitivityX; } float scroll = Input.GetAxisRaw("Mouse ScrollWheel"); targetDollyDis -= scroll * mouseScrollMult; targetDollyDis = Mathf.Clamp(targetDollyDis, 5, 500); dollyDis = AnimMath.Slide(dollyDis, targetDollyDis, .05f); // EASE cam.transform.localPosition = new Vector3(0, 0, -dollyDis); // changing rotation to match the pitch variable: pitch = Mathf.Clamp(pitch, -89, 89); Quaternion targetRotation = Quaternion.Euler(pitch, yaw, roll); transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, 0.01f); // EASE }
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); }
/// <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); }
/// <summary> /// Camera orbits around the player when the player moves the mouse around /// </summary> private void PlayerOrbitCamera() { // Gets 'float' input when the player moves the mouse float mX = Input.GetAxisRaw("Mouse X"); float mY = Input.GetAxisRaw("Mouse Y"); // Gets yaw and pitch yaw += mX * cameraSensitivityX; pitch += mY * cameraSensitivityY; if (IsTargeting()) // x-targeting: // if targeting { pitch = Mathf.Clamp(pitch, 15, 60); // find player yaw float playerYaw = moveScript.transform.eulerAngles.y; // clamp camera-rig yaw to playerYaw +- 30 yaw = Mathf.Clamp(yaw, playerYaw - 40, playerYaw + 40); } else // not targeting / free look { pitch = Mathf.Clamp(pitch, -10, 89); // clamps pitch to not get stuck } transform.rotation = AnimMath.Slide(transform.rotation, Quaternion.Euler(pitch, yaw, 0), .001f); // makes camera have a smooth transition when moving it }
private void CheckForDeath() { if (healthCheck.isDying) // if sentry dies set trigger and keep from targeting player { dyingTrigger = true; isClose = false; //below sets it so the sentry is not a shootable target anymore for player isShootable.enabled = false; } //This triggers Death Animation which is the sentry spinning and shaking on the x and z rotations vigorusly if (dyingTrigger && dyingTimer > 0) { //Used mathf.Sin to make snetry rotate back and forth on x and z float betweenX = Mathf.Sin(Time.time * 40) * 25f; float betweenZ = Mathf.Sin(Time.time * 5) * 5f; turnVar += (turnSpeed + 100) * Time.deltaTime; // for y rotation Quaternion turnRot = Quaternion.Euler(betweenX, turnVar, betweenZ); //creates rotation transform.localRotation = AnimMath.Slide(transform.localRotation, turnRot, 0.001f); //smooth transition to rotation dyingTimer -= 1 * Time.deltaTime; //countdown } if (dyingTimer <= 0.01f) { Instantiate(parts, GunParent.position, GunParent.rotation); // this spawns death particles for sentry AudioP.Play(); } if (dyingTimer <= 0) // this destroys sentry object after death animation is complete { PlayerTargeting.enemiesKilled += 1; Destroy(GunParent.gameObject); } }
void Update() { goToPlanet(); transform.position = AnimMath.Slide(transform.position, target, .05f); if (Input.GetButton("Fire2")) { float mouseX = Input.GetAxis("Mouse X"); float mouseY = Input.GetAxis("Mouse Y"); targetYaw += mouseX * mouseSensitivityX; targetPitch += mouseY * mouseSensitivityY; } float scroll = Input.GetAxisRaw("Mouse ScrollWheel"); targetZoomDis += scroll * mouseScrollMultiplier; targetZoomDis = Mathf.Clamp(targetZoomDis, 2.5f, 15f); zoomDis = AnimMath.Slide(zoomDis, targetZoomDis, .05f); cam.transform.localPosition = new Vector3(0, 0, -zoomDis); targetPitch = Mathf.Clamp(targetPitch, -89, 89); pitch = AnimMath.Slide(pitch, targetPitch, .05f); yaw = AnimMath.Slide(yaw, targetYaw, .05f); transform.rotation = Quaternion.Euler(pitch, yaw, 0); }
public void DoTheLerp(float p) { transform.position = AnimMath.Lerp( objectStart.transform.position, objectEnd.transform.position, p); }
// Update is called once per frame void Update() { EaseTarget = CalcPosition(); transform.position = AnimMath.Dampen(transform.position, EaseTarget, .05f); if (IsPlayingForward) { LittleTime += Time.deltaTime; if (LittleTime >= BigTime) { IsPlayingForward = false; } } else { LittleTime -= Time.deltaTime; if (LittleTime <= 0) { IsPlayingForward = true; } } //CalcPosition(); }
/// <summary> /// Slide turret's head back to where is was before /// </summary> private void PutTurretHome() { turretHead.localPosition = AnimMath.Slide(turretHead.localPosition, startPosTurretHead, .01f); // slides turret head to its start position Vector3 gunBarrel = turretHead.localPosition; // The gunBarrel get the localPosition Mathf.Clamp(turretHead.localPosition.x, gunBarrel.x = 0, gunBarrel.x = 0); // clamps turret head at x axis 0 }
private void TurnTowardsTarget() { Vector3 disToTarget = Player.transform.position - transform.position; Quaternion targetRotation = Quaternion.LookRotation(disToTarget, Vector3.up); Vector3 euler1 = transform.localEulerAngles; // get local angles BEFORE rotation Quaternion prevRot = transform.rotation; transform.rotation = targetRotation; // set rotation Vector3 euler2 = transform.localEulerAngles; // get local angles AFTER rotation if (lockRotationX) { euler2.x = euler1.x; // revert x to previous value } if (lockRotationY) { euler2.y = euler1.y; // revert y to previous value } if (lockRotationZ) { euler2.z = euler1.z; // revert z to previous value } transform.rotation = prevRot; // revert rotation // animate rotation transform.localRotation = AnimMath.Slide(transform.localRotation, Quaternion.Euler(euler2), .01f); }
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 IdleAndAttackAnimation() { if (!isClose && idleTimer > 0 && !idleTrigger) // will make sentry go back to rotating idle animation if loses sight of player starting at 0,0,0 { lookingRotation = Quaternion.Euler(0, 0, 0); transform.localRotation = AnimMath.Slide(transform.localRotation, lookingRotation, 0.09f); idleTimer -= 1 * Time.deltaTime; } else if (isClose) //if player is close triggers part of attack animation, aka: sentry aiming at player when close { idleTimer = 1f; Vector3 disToTarget = Player.position - transform.position; Quaternion targetRotation = Quaternion.LookRotation(disToTarget, Vector3.up); transform.localRotation = AnimMath.Slide(transform.localRotation, targetRotation, 0.001f); } else if (idleTrigger) //idle animation for sentry { turnVar += turnSpeed * Time.deltaTime; Quaternion dieRot = Quaternion.Euler(transform.localRotation.x, turnVar, transform.localRotation.z); transform.localRotation = AnimMath.Slide(transform.localRotation, dieRot, 0.01f); } if (idleTimer <= 0) //Makes it so there is a slight pause before turret goes from 0,0,0 to rotating in idle mode { idleTrigger = true; } }
// Update is called once per frame void Update() { if (Input.GetButton("Fire2")) { // Changing the pitch float mouseY = Input.GetAxis("Mouse Y"); float mouseX = Input.GetAxis("Mouse X"); targetPitch += mouseY * mouseSensitivityY; targetYaw += mouseX * mouseSensitivityX; } float scroll = Input.GetAxisRaw("Mouse ScrollWheel"); targetDollyDis += scroll * mouseScrollMultiplier; targetDollyDis = Mathf.Clamp(targetDollyDis, 2.5f, 15); dollyDis = AnimMath.Slide(dollyDis, targetDollyDis, .05f); // EASE cam.transform.localPosition = new Vector3(0, 0, -dollyDis); // Changing the rotation to match the pitch variable targetPitch = Mathf.Clamp(targetPitch, -89, 89); pitch = AnimMath.Slide(pitch, targetPitch, .05f); //EASE yaw = AnimMath.Slide(yaw, targetYaw, .05f); //EASE // Quaternion targetRotation transform.rotation = Quaternion.Euler(pitch, yaw, 0); //transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, 0.01f); // Could use .Slerp }
// Update is called once per frame void Update() { if (Input.GetButton("Fire2")) { float mouseY = Input.GetAxis("Mouse Y"); targetPitch += mouseY * mouseSensitivityY; float mouseX = Input.GetAxis("Mouse X"); targetPitch2 += mouseX * mouseSensitivityX; } float scroll = Input.GetAxisRaw("Mouse ScrollWheel"); targetDis += scroll * scrollSense; cam.transform.localPosition = new Vector3(0, 0, -dis); dis = AnimMath.Slide(dis, targetDis, .05f); //ease targetDis = Mathf.Clamp(targetDis, 2.5f, 15f); targetPitch = Mathf.Clamp(targetPitch, -89, 89); pitch = AnimMath.Slide(pitch, targetPitch, .05f); //ease pitch2 = AnimMath.Slide(pitch2, targetPitch2, .05f); //eASE transform.rotation = Quaternion.Euler(pitch, pitch2, 0); }
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() { 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; } }
void Update() { if (Input.GetButton("Fire1")) // On Left Click { // Change Pitch on Mouse1 float mouseY = Input.GetAxis("Mouse Y"); float mouseX = Input.GetAxis("Mouse X"); targetYaw += mouseX * mouseSensitivityX; targetPitch += mouseY * mouseSensitivityY; } float scroll = Input.GetAxisRaw("Mouse ScrollWheel"); // Scoll mousewheel to change DollyDis targetDollyDis += scroll * mouseScrollMultiplier; targetDollyDis = Mathf.Clamp(targetDollyDis, 2.5f, 15f); dollyDis = AnimMath.Slide(dollyDis, targetDollyDis, .95f); // EASE cam.transform.localPosition = new Vector3(0, 0, -dollyDis); targetPitch = Mathf.Clamp(targetPitch, -89, 89); pitch = AnimMath.Slide(pitch, targetPitch, .95f); // EASE yaw = AnimMath.Slide(yaw, targetYaw, .95f); // EASE //Quaternion targetRotation = Quaternion.Euler(pitch, yaw, 0); //transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, 0.01f); // Slerp can be used for a spherical rotation transform.rotation = Quaternion.Euler(pitch, yaw, 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; } }
// 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
private void PlayerOrbitCamera() { float mx = Input.GetAxisRaw("Mouse X"); float my = Input.GetAxisRaw("Mouse Y"); yaw += mx * cameraSensitivityX; pitch += my * cameraSensitivityY; if (IsTargeting()) // z-targeting: { pitch = Mathf.Clamp(pitch, 15, 60); // find player yaw: float playerYaw = moveScript.transform.eulerAngles.y; // clamp camera-rig yaw to playerYaw +- 30: yaw = Mathf.Clamp(yaw, playerYaw - 40, playerYaw + 40); } else // not targeting / free look: { pitch = Mathf.Clamp(pitch, -10, 89); } transform.rotation = AnimMath.Slide(transform.rotation, Quaternion.Euler(pitch, yaw, 0), .001f); }
private void TurnTowardsTheTarget() { if (playerTargeting && playerTargeting.target && playerTargeting.wantsToTarget) { Vector3 disToTarget = playerTargeting.target.position - transform.position; Quaternion targetRotation = Quaternion.LookRotation(disToTarget, Vector3.up); Vector3 euler1 = transform.localEulerAngles; Quaternion prevRot = transform.rotation; transform.rotation = targetRotation; Vector3 euler2 = transform.localEulerAngles; if (lockRotationX) { euler2.x = euler1.x; } if (lockRotationY) { euler2.y = euler1.y; } if (lockRotationZ) { euler2.z = euler1.z; } transform.rotation = prevRot; transform.localRotation = AnimMath.Slide(transform.localRotation, Quaternion.Euler(euler2), .01f); } else { transform.localRotation = AnimMath.Slide(transform.localRotation, startingRotation, .05f); } }
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); } } }
/// <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); }
public void TurnTowardsPlayer() { Vector3 disToTarget = target.position - transform.position; Quaternion targetRotation = Quaternion.LookRotation(disToTarget, Vector3.up); transform.rotation = AnimMath.Slide(transform.rotation, targetRotation, .01f); }
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 AimAtPlayer() { Vector3 disToTarget = Player.transform.position - transform.position; Quaternion targetRot = Quaternion.LookRotation(disToTarget, Vector3.up); Vector3 euler1 = transform.localEulerAngles; Quaternion prevRot = transform.rotation; transform.rotation = targetRot; Vector3 euler2 = transform.localEulerAngles; if (lockRotationX) { euler2.x = euler1.x; } if (lockRotationY) { euler2.y = euler1.y; } if (lockRotationZ) { euler2.z = euler1.z; } transform.rotation = prevRot; transform.localRotation = AnimMath.Slide(transform.localRotation, Quaternion.Euler(euler2), .01f); }