Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RandomMove : MonoBehaviour
- {
- public bool Move = true;
- public bool Rotate = true;
- public float MoveSpeed = 1f;
- public float MoveAmount = 1f;
- public float RotateSpeed = 1f;
- public float RotateAmount = 5f;
- private float offset;
- void Start()
- {
- offset = Random.Range(0, 1000);
- }
- void Update()
- {
- if (Move)
- {
- var x = -0.5f + Mathf.PerlinNoise(100 + Mathf.Sin(offset + Time.time * MoveSpeed), 100 + Mathf.Cos(offset + Time.time * MoveSpeed));
- var y = -0.5f + Mathf.PerlinNoise(100 + Mathf.Sin(offset + Time.time * MoveSpeed) + 10, 100 + Mathf.Cos(offset + Time.time * MoveSpeed) + 5);
- transform.localPosition = new Vector3(x * MoveAmount, y * MoveAmount, 0f);
- }
- if (Rotate)
- {
- var r = -0.5f + Mathf.PerlinNoise(1f + Mathf.Sin(offset + Time.time * RotateSpeed) + 10, 1f + Mathf.Cos(offset + Time.time * RotateSpeed) + 29);
- transform.localRotation = Quaternion.Euler(0f, r * RotateAmount, 0f);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement