I’ve instantiated three game objects at designated positions and I want them to hover in place when they appear. I tried using Vector3 * Mathf.Cos to oscillate the object; however, while this does make the object hover, this moves the object from the selected location of instantiation to the X: 0, Y: 0, Z: 0 position. What could be causing this? I’m new to Unity so anything helps! Thanks!
Check out this script I wrote for my item drops some time in the past:
public class ItemDropRotation : MonoBehaviour
{
[SerializeField] private float _rotationSpeed = 30.0f;
[SerializeField] private float _bopHeight = 0.03f;
[SerializeField] private float _bopSpeed = 1.0f;
void Update()
{
transform.Rotate(Vector3.up, (_rotationSpeed * Time.deltaTime));
if (transform.rotation.eulerAngles.y > 180) _rotationSpeed *= -1;
transform.Translate(new Vector3(0, Mathf.Sin(Time.time) * _bopHeight, 0)* _bopSpeed * Time.deltaTime);
}
}