Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class FloatingObject_Script : MonoBehaviour
- {
- /// <summary>
- /// The Pitch Amplitude
- /// </summary>
- public float pitch;
- /// <summary>
- /// The Yaw Amplitude
- /// </summary>
- public float yaw;
- /// <summary>
- /// The Roll Amplitude
- /// </summary>
- public float roll;
- /// <summary>
- /// The Frequency
- /// </summary>
- public float frequency = 1.0f;
- /// <summary>
- /// The Amplitude
- /// </summary>
- public float amplitude = 0.5f;
- /// <summary>
- /// Private variables
- /// </summary>
- private Vector3 _originalPosition;
- private Quaternion _originalRotation;
- void Start()
- {
- _originalPosition = transform.position;
- _originalRotation = transform.rotation;
- }
- void Update()
- {
- float calculatedSin = Mathf.Sin(Time.fixedTime * Mathf.PI * frequency);
- float newPitch = calculatedSin * pitch;
- float newYaw = calculatedSin * yaw;
- float newRoll = calculatedSin * roll;
- float newY = calculatedSin * amplitude + _originalPosition.y;
- // Apply the new rotation and position.
- transform.rotation = Quaternion.Euler(newPitch, newYaw, newRoll) * _originalRotation;
- transform.position = new Vector3(_originalPosition.x,newY,_originalPosition.z);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement