Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using FIMSpace.Basics;
- using FIMSpace.FLook;
- using FIMSpace.FSpine;
- using FIMSpace.FTail;
- using FIMSpace.GroundFitter;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class FImpossibleDragon : FGroundFitter_MovementLook
- {
- #region Looking Stuff
- public LayerMask lookLayerMask = 1 << 0;
- private FLookAnimator look;
- private float smoothBackBonesOffset;
- private Vector3 targetLookPos;
- #endregion
- private FSpineAnimator spine;
- private List<FTail_AnimatorBlending> wings;
- private FBasic_TPPCameraBehaviour tpp;
- private float doubleClickTimer = 0f;
- private bool MoveForward;
- private bool flying = false;
- private Quaternion targetFlyRotation;
- private float verticalFlySpeed = 0f;
- private bool startFlyBoosting = false;
- protected override void Start()
- {
- base.Start();
- look = GetComponent<FLookAnimator>();
- smoothBackBonesOffset = look.BackBonesAddOffset.z;
- spine = GetComponent<FSpineAnimator>();
- wings = FTransformMethods.FindComponentsInAllChildren<FTail_AnimatorBlending>(transform);
- tpp = Camera.main.GetComponent<FBasic_TPPCameraBehaviour>();
- clips.AddClip("JumpUp");
- clips.AddClip("FallToLanding");
- clips.AddClip("ToFly");
- clips.AddClip("FlyStationary");
- clips.AddClip("flyNormal");
- clips.AddClip("glide");
- }
- protected override void Update()
- {
- base.Update();
- if (MoveVector == Vector3.forward)
- MoveForward = true;
- else
- MoveForward = false;
- #region Looking Stuff
- if (targetOfLook)
- {
- targetOfLook.position = Vector3.Lerp(targetOfLook.position, targetLookPos, Time.deltaTime * 8f);
- }
- // - 70 to 90
- RaycastHit lookHit;
- Ray lookRay = new Ray(look.BackBonesTransforms[look.BackBonesCount - 1].position, Quaternion.Euler(0f, fitter.UpAxisRotation, 0f) * Vector3.forward);
- Physics.Raycast(lookRay, out lookHit, 6f, lookLayerMask, QueryTriggerInteraction.Ignore);
- if (lookHit.transform)
- {
- float dist = Vector3.Distance(lookRay.origin, lookHit.point);
- smoothBackBonesOffset = Mathf.Lerp(smoothBackBonesOffset, Mathf.Lerp(-70f, 90f, Mathf.InverseLerp(6f, 3f, dist)), Time.deltaTime * 4f);
- }
- else
- {
- smoothBackBonesOffset = Mathf.Lerp(smoothBackBonesOffset, -70f, Time.deltaTime * 2.5f);
- }
- look.BackBonesAddOffset = new Vector3(0f, 0f, smoothBackBonesOffset);
- #endregion
- if (inAir)
- foreach (var wing in wings) wing.BlendToOriginal = Mathf.Lerp(wing.BlendToOriginal, 0.7f, Time.deltaTime * 4f);
- else
- foreach (var wing in wings) wing.BlendToOriginal = Mathf.Lerp(wing.BlendToOriginal, 0.0f, Time.deltaTime * 1f);
- if (flying)
- {
- tpp.FollowingOffset = new Vector3(0f, Mathf.Lerp(tpp.FollowingOffset.y, 5.31f, Time.deltaTime * 2f));
- if (!MoveForward)
- spine.GoBackSpeed = Mathf.Lerp(spine.GoBackSpeed, 0.25f, Time.deltaTime * 4f);
- else
- spine.GoBackSpeed = Mathf.Lerp(spine.GoBackSpeed, 0.0f, Time.deltaTime * 4f);
- }
- else
- {
- tpp.FollowingOffset = new Vector3(0f, Mathf.Lerp(tpp.FollowingOffset.y, 1.8f, Time.deltaTime * 2f));
- }
- doubleClickTimer -= Time.deltaTime;
- }
- protected override void HandleAnimations()
- {
- if (!flying)
- {
- if (inAir)
- {
- if (YVelocity < -3f) CrossfadeTo("FallToLanding", 0.7f);
- }
- else
- {
- if (ActiveSpeed > 0.15f)
- {
- if (Sprint)
- CrossfadeTo("Run", 0.25f);
- else
- CrossfadeTo("Walk", 0.25f);
- }
- else
- {
- CrossfadeTo("Idle", 0.25f);
- }
- }
- FAnimatorMethods.LerpFloatValue(animator, "AnimationSpeed", MultiplySprintAnimation ? (ActiveSpeed / BaseSpeed) : Mathf.Min(1f, (ActiveSpeed / BaseSpeed)));
- }
- else
- {
- if (!startFlyBoosting)
- {
- float targetAnimSpeed = 1f;
- if (MoveForward)
- {
- CrossfadeTo("flyNormal");
- }
- else
- {
- if (ActiveSpeed > SprintingSpeed) CrossfadeTo("glide");
- else
- if (ActiveSpeed > BaseSpeed) CrossfadeTo("flyNormal");
- else
- CrossfadeTo("FlyStationary");
- }
- targetAnimSpeed = Mathf.Clamp(ActiveSpeed / (SprintingSpeed * 1.5f), 1f, 1.8f);
- FAnimatorMethods.LerpFloatValue(animator, "AnimationSpeed", targetAnimSpeed, 3f);
- }
- }
- }
- protected override void HandleGravity()
- {
- if (!flying)
- {
- base.HandleGravity();
- }
- else
- {
- if (!startFlyBoosting)
- {
- RaycastHit groundHit = fitter.CastRay();
- if (groundHit.transform)
- {
- if (Mathf.Abs(groundHit.point.y - transform.position.y) < 0.25f)
- {
- flying = false;
- RefreshHitGroundVars(groundHit);
- YVelocity = -ActiveSpeed * transform.rotation.eulerAngles.normalized.y;
- fitter.UpAxisRotation = transform.rotation.eulerAngles.y;
- }
- }
- }
- }
- }
- protected override void HandleTransforming()
- {
- if (!flying)
- {
- base.HandleTransforming();
- }
- else
- {
- fitter.enabled = false;
- inAir = true;
- targetFlyRotation = Camera.main.transform.rotation;
- targetFlyRotation = Quaternion.Euler(targetFlyRotation.eulerAngles.x - 25f, targetFlyRotation.eulerAngles.y + RotationOffset, targetFlyRotation.eulerAngles.z);
- if (MoveForward)
- {
- if (!Sprint)
- ActiveSpeed = Mathf.Lerp(ActiveSpeed, BaseSpeed * 3f, delta * AccelerationSpeed * 0.5f);
- else
- ActiveSpeed = Mathf.Lerp(ActiveSpeed, SprintingSpeed * 3f, delta * AccelerationSpeed * 0.35f);
- }
- else
- {
- ActiveSpeed = Mathf.Lerp(ActiveSpeed, -0.05f, Time.deltaTime * 0.75f);
- if (ActiveSpeed < 0f) ActiveSpeed = 0f;
- }
- transform.rotation = Quaternion.Slerp(transform.rotation, targetFlyRotation, Time.deltaTime * 3f);
- transform.position += transform.forward * ActiveSpeed * delta;
- if (Input.GetKey(KeyCode.LeftControl)) ActiveSpeed = Mathf.Lerp(ActiveSpeed, 0f, Time.deltaTime * 1f);
- if (Input.GetKey(KeyCode.Space)) verticalFlySpeed = Mathf.Lerp(verticalFlySpeed, 1f, Time.deltaTime);
- else
- if (Input.GetKey(KeyCode.Z)) verticalFlySpeed = Mathf.Lerp(verticalFlySpeed, -1f, Time.deltaTime);
- else
- verticalFlySpeed = Mathf.Lerp(verticalFlySpeed, 0f, Time.deltaTime * 3f);
- transform.position += Vector3.up * verticalFlySpeed * 20f * delta;
- SetLookAtPosition(transform.position + Camera.main.transform.forward * 10f + Vector3.up);
- }
- }
- public override void Jump()
- {
- base.Jump();
- CrossfadeTo("JumpUp", 0.5f);
- if (doubleClickTimer > 0f) StartFlying();
- doubleClickTimer = 0.5f;
- }
- private void StartFlying()
- {
- flying = true;
- CrossfadeTo("ToFly", 0.5f);
- StartCoroutine(StartFlyBoost());
- }
- private IEnumerator StartFlyBoost()
- {
- startFlyBoosting = true;
- float time = 0f;
- while (time < 0.5f)
- {
- time += Time.deltaTime;
- transform.position += Vector3.up * delta * 11f;
- yield return null;
- }
- startFlyBoosting = false;
- }
- protected override void HitGround()
- {
- base.HitGround();
- StartCoroutine(StraightenSpine());
- }
- private IEnumerator StraightenSpine()
- {
- while (spine.GoBackSpeed < 0.5f)
- {
- spine.GoBackSpeed = Mathf.Lerp(spine.GoBackSpeed, 0.55f, Time.deltaTime * 5f);
- yield return null;
- }
- while (spine.GoBackSpeed > 0f)
- {
- spine.GoBackSpeed = Mathf.Lerp(spine.GoBackSpeed, -0.05f, Time.deltaTime * 5f);
- yield return null;
- }
- spine.GoBackSpeed = 0f;
- }
- //protected override void SetLookAtPosition(Vector3 tPos)
- //{
- // targetLookPos = tPos;
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement