From b3ff205e699704582c81a653988a7f5759855268 Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 2 Aug 2025 17:08:57 -0400 Subject: [PATCH] added: simple scripts for object movement --- Assets/SinMovement.cs | 20 ++++++++++++++++++++ Assets/SinMovement.cs.meta | 2 ++ Assets/SwayMovement.cs | 25 +++++++++++++++++++++++++ Assets/SwayMovement.cs.meta | 2 ++ 4 files changed, 49 insertions(+) create mode 100644 Assets/SinMovement.cs create mode 100644 Assets/SinMovement.cs.meta create mode 100644 Assets/SwayMovement.cs create mode 100644 Assets/SwayMovement.cs.meta diff --git a/Assets/SinMovement.cs b/Assets/SinMovement.cs new file mode 100644 index 0000000..8d865b9 --- /dev/null +++ b/Assets/SinMovement.cs @@ -0,0 +1,20 @@ +using UnityEngine; + +public class SinMovement : MonoBehaviour{ + private float originalY; + + public float speed; + public float scale; + + public float offset; + + void Start(){ + originalY = transform.position.y; + offset += Random.Range(-1, 1); + } + + // Update is called once per frame + void Update(){ + transform.position = transform.position.Flatten(null, originalY + Mathf.Sin((Time.time + offset) * speed) * scale, null); + } +} diff --git a/Assets/SinMovement.cs.meta b/Assets/SinMovement.cs.meta new file mode 100644 index 0000000..f8336d2 --- /dev/null +++ b/Assets/SinMovement.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: e33277577aa379a41a747f01aade9c96 \ No newline at end of file diff --git a/Assets/SwayMovement.cs b/Assets/SwayMovement.cs new file mode 100644 index 0000000..a69adea --- /dev/null +++ b/Assets/SwayMovement.cs @@ -0,0 +1,25 @@ +using UnityEngine; + +public class SwayMovement : MonoBehaviour{ + Vector3 originalRot; + public Vector3 swayAmount; + public Vector3 swaySpeed; + + private Vector3 offset; + + void Start(){ + originalRot = transform.rotation.eulerAngles; + offset = new Vector3(Random.Range(-5, 1), Random.Range(-1, 5), Random.Range(-3, 1)); + } + + // Update is called once per frame + void Update(){ + Vector3 sway = new Vector3( + originalRot.x + Mathf.Sin((Time.time + offset.x) * swaySpeed.x) * swayAmount.x, + originalRot.y + Mathf.Sin((Time.time + offset.y) * swaySpeed.y) * swayAmount.y, + originalRot.z + Mathf.Sin((Time.time + offset.z) * swaySpeed.z) * swayAmount.z + ); + + transform.rotation = Quaternion.Euler(sway); + } +} diff --git a/Assets/SwayMovement.cs.meta b/Assets/SwayMovement.cs.meta new file mode 100644 index 0000000..08fe320 --- /dev/null +++ b/Assets/SwayMovement.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 57870c7b66535c74688188df7e771ce7 \ No newline at end of file