Advertisement
jamieTheCoder

DoTweenTest

Oct 14th, 2022
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.93 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using DG.Tweening;
  4. using MoreMountains.CorgiEngine;
  5. using MoreMountains.Tools;
  6. using UnityEngine;
  7.  
  8. public class DoTweenTest : MonoBehaviour {
  9.     /// <summary>
  10.     /// We need to add some checks to see if snap speed is more than speed randomness
  11.     /// Other than that I think This is a good start
  12.     ///
  13.     ///
  14.     ///
  15.     /// TODO - Change COROUTINE to ASYNC (Maybe That Will Fix The Jitter)IDK;
  16.     /// </summary>
  17.  
  18.     [Header ("Default Values Before Any Randomness")]
  19.     [SerializeField] float baseReactionTime;
  20.     [Header ("Random Time")]
  21.     [SerializeField] float SnapSpeedMin;
  22.     [SerializeField] float SnapSpeedMax, ReactionTimeRandomnessMin, ReactionTimeRandomnessMax;
  23.     [Header ("Read Only")]
  24.     [MMReadOnly][SerializeField] float ReactionTimeRandomness, SnapSpeed;
  25.     [MMReadOnly][SerializeField] Vector3 LastPos, customVector, currentPlayerPos;
  26.     [MMReadOnly][SerializeField] private GameObject player;
  27.     [Header ("Experimental(Perlin Noise Vector3 Settings (Being a Pain!!!!!))")]
  28.     // Distance covered per second along X axis of Perlin plane.
  29.     [SerializeField] float xScale = 1.0f;
  30.     // Vector added to Lerped Value
  31.     [SerializeField] Vector3 pos;
  32.     //Lower = smaller Noise Values(Might Want to do clamping Instead)
  33.     [Range (0, 1)][SerializeField] float PerlinNoiseMult;
  34.     [Range (0, 1)][SerializeField] float PerlinNoiseMax;
  35.     [Range (0, 1)][SerializeField] float PerlinNoiseMin;
  36.     [Header ("DONT Touch(Debug Tool)")]
  37.     [SerializeField] bool runScript;
  38.  
  39.     private void Update () {
  40.        
  41.        
  42.         //This noise is being a pain
  43.         float height = PerlinNoiseMult * Mathf.PerlinNoise (Time.time * xScale, 0.0f);
  44.         float clampedHeight = Mathf.Clamp(height,PerlinNoiseMin,PerlinNoiseMax);
  45.         pos.y = clampedHeight;
  46.         customVector += pos;
  47.         //This Is the real Meat and Potatoes - Line 47 (is really all we need)
  48.         transform.position = customVector;
  49.     }
  50.  
  51.     IEnumerator MoveToPlayer () {
  52.         DOTween.To (() => customVector, x => customVector = x, currentPlayerPos, SnapSpeed).SetEase (Ease.InSine);
  53.         yield return new WaitForSeconds (baseReactionTime - SnapSpeed + ReactionTimeRandomness);
  54.         updatePlayerPos ();
  55.     }
  56.  
  57.     //this function should only be ran by the player
  58.     public void SetPlayerGameObject (GameObject tempPlayer) {
  59.         player = tempPlayer;
  60.         updatePlayerPos ();
  61.     }
  62.  
  63.     public void updatePlayerPos () {
  64.         if (runScript) {
  65.             //we also call this on a script on start on the player
  66.             currentPlayerPos = player.transform.position;
  67.             SetRandomVariables ();
  68.         } else { return; }
  69.     }
  70.  
  71.     private void SetRandomVariables () {
  72.         SnapSpeed = Random.Range (SnapSpeedMin, SnapSpeedMax);
  73.         ReactionTimeRandomness = Random.Range (ReactionTimeRandomnessMin, ReactionTimeRandomnessMax);
  74.         StartCoroutine (MoveToPlayer ());
  75.     }
  76.  
  77.     //These Should only be called from outside this script
  78.     public void StartShootLine () {
  79.         runScript = true;
  80.         updatePlayerPos ();
  81.     }
  82.  
  83.     public void StopShootLine () {
  84.         runScript = false;
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement