Advertisement
apieceoffruit

Tronds random wiggle script

Jul 12th, 2021 (edited)
1,142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. public class RandomMove : MonoBehaviour
  2. {
  3.     public bool Move = true;
  4.     public bool Rotate = true;
  5.  
  6.     public float MoveSpeed = 1f;
  7.     public float MoveAmount = 1f;
  8.     public float RotateSpeed = 1f;
  9.     public float RotateAmount = 5f;
  10.  
  11.     private float offset;
  12.    
  13.     void Start()
  14.     {
  15.         offset = Random.Range(0, 1000);
  16.     }
  17.    
  18.     void Update()
  19.     {
  20.         if (Move)
  21.         {
  22.             var x = -0.5f + Mathf.PerlinNoise(100 + Mathf.Sin(offset + Time.time * MoveSpeed), 100 + Mathf.Cos(offset + Time.time * MoveSpeed));
  23.             var y = -0.5f + Mathf.PerlinNoise(100 + Mathf.Sin(offset + Time.time * MoveSpeed) + 10, 100 + Mathf.Cos(offset + Time.time * MoveSpeed) + 5);
  24.             transform.localPosition = new Vector3(x * MoveAmount, y * MoveAmount, 0f);
  25.         }
  26.        
  27.         if (Rotate)
  28.         {
  29.             var r = -0.5f + Mathf.PerlinNoise(1f + Mathf.Sin(offset + Time.time * RotateSpeed) + 10, 1f + Mathf.Cos(offset + Time.time * RotateSpeed) + 29);
  30.             transform.localRotation = Quaternion.Euler(0f, r * RotateAmount, 0f);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement