Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using DG.Tweening;
- using MoreMountains.CorgiEngine;
- using MoreMountains.Tools;
- using UnityEngine;
- public class DoTweenTest : MonoBehaviour {
- /// <summary>
- /// We need to add some checks to see if snap speed is more than speed randomness
- /// Other than that I think This is a good start
- ///
- ///
- ///
- /// TODO - Change COROUTINE to ASYNC (Maybe That Will Fix The Jitter)IDK;
- /// </summary>
- [Header ("Default Values Before Any Randomness")]
- [SerializeField] float baseReactionTime;
- [Header ("Random Time")]
- [SerializeField] float SnapSpeedMin;
- [SerializeField] float SnapSpeedMax, ReactionTimeRandomnessMin, ReactionTimeRandomnessMax;
- [Header ("Read Only")]
- [MMReadOnly][SerializeField] float ReactionTimeRandomness, SnapSpeed;
- [MMReadOnly][SerializeField] Vector3 LastPos, customVector, currentPlayerPos;
- [MMReadOnly][SerializeField] private GameObject player;
- [Header ("Experimental(Perlin Noise Vector3 Settings (Being a Pain!!!!!))")]
- // Distance covered per second along X axis of Perlin plane.
- [SerializeField] float xScale = 1.0f;
- // Vector added to Lerped Value
- [SerializeField] Vector3 pos;
- //Lower = smaller Noise Values(Might Want to do clamping Instead)
- [Range (0, 1)][SerializeField] float PerlinNoiseMult;
- [Range (0, 1)][SerializeField] float PerlinNoiseMax;
- [Range (0, 1)][SerializeField] float PerlinNoiseMin;
- [Header ("DONT Touch(Debug Tool)")]
- [SerializeField] bool runScript;
- private void Update () {
- //This noise is being a pain
- float height = PerlinNoiseMult * Mathf.PerlinNoise (Time.time * xScale, 0.0f);
- float clampedHeight = Mathf.Clamp(height,PerlinNoiseMin,PerlinNoiseMax);
- pos.y = clampedHeight;
- customVector += pos;
- //This Is the real Meat and Potatoes - Line 47 (is really all we need)
- transform.position = customVector;
- }
- IEnumerator MoveToPlayer () {
- DOTween.To (() => customVector, x => customVector = x, currentPlayerPos, SnapSpeed).SetEase (Ease.InSine);
- yield return new WaitForSeconds (baseReactionTime - SnapSpeed + ReactionTimeRandomness);
- updatePlayerPos ();
- }
- //this function should only be ran by the player
- public void SetPlayerGameObject (GameObject tempPlayer) {
- player = tempPlayer;
- updatePlayerPos ();
- }
- public void updatePlayerPos () {
- if (runScript) {
- //we also call this on a script on start on the player
- currentPlayerPos = player.transform.position;
- SetRandomVariables ();
- } else { return; }
- }
- private void SetRandomVariables () {
- SnapSpeed = Random.Range (SnapSpeedMin, SnapSpeedMax);
- ReactionTimeRandomness = Random.Range (ReactionTimeRandomnessMin, ReactionTimeRandomnessMax);
- StartCoroutine (MoveToPlayer ());
- }
- //These Should only be called from outside this script
- public void StartShootLine () {
- runScript = true;
- updatePlayerPos ();
- }
- public void StopShootLine () {
- runScript = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement