Hello, I am attempting to make a rocket that has a nice circular wobble around whichever direction it is flying. I have created a vector3 using sin and cos that can make an object rotate in a circle around it’s up axis. However, I don’t seem to know how to properly do the math to add this to the rocket, which can be at any arbitrary angle it finds itself in.
My goal is that depending on the rate and magnitude, the rocket will fly more out of control, as if it is damaged or not calibrated correctly, making a corkscrew path.
I left a couple lines of commented out test code in. I’m running out of ideas on how properly implement this. Any guidance would be much appreciated. Thank you.
using UnityEngine;
using System.Collections;
public class wobbleCS : MonoBehaviour {
public float wobbleRate = 10;
public float wobbleMag = 0;
// Update is called once per frame
void FixedUpdate () {
Vector3 rocketWobble = new Vector3(wobbleMag *(Mathf.Sin(Time.time * wobbleRate) ), 0, wobbleMag * (Mathf.Cos(Time.time * wobbleRate) ) );
Debug.Log("Debug: " + rocketWobble.x + ", " + rocketWobble.z + ". ");
//transform.rotation = Quaternion.Euler(rocketWobble); // makes a nice circle around the up axis
//transform.Rotate(Quaternion.Euler(rocketWobble).eulerAngles, Space.Self); //this results in crooked rotations
transform.rotation = Quaternion.Euler(rocketWobble) * transform.rotation; // identical results as the line above I believe
}
}