<aside> 📄 This script makes an object float in your scene, but offers controllable parameters for speed, rotation, and movement. Attach it directly to the GameObject that you want to
</aside>
using UnityEngine;
public class ObjectFloat : MonoBehaviour
{
public float rotationSpeed = 30.0f; // Rotation speed in degrees per second
public float rotationDirection = 1.0f; // Rotation direction: 1 for clockwise, -1 for counter-clockwise
public float movementSpeed = 2.0f; // Movement speed in units per second
public float movementRadius = 2.0f; // Movement radius of the circular motion
public float floatiness = 1.0f; // Adjust the floatiness of the object
private float currentAngle = 0.0f;
private void Update()
{
// Rotation motion
float rotationAmount = rotationSpeed * rotationDirection * Time.deltaTime;
transform.Rotate(Vector3.up, rotationAmount);
// Circular motion
currentAngle += movementSpeed * Time.deltaTime;
float x = Mathf.Cos(currentAngle) * movementRadius;
float y = Mathf.Sin(currentAngle) * movementRadius;
transform.position = new Vector3(x, y, 0.0f);
// Floating motion
float floatY = Mathf.Sin(Time.time) * floatiness;
transform.position += new Vector3(0.0f, floatY, 0.0f);
}
}