- Home /
Question by
richwarp · Jan 08, 2021 at 09:16 PM ·
scripting problemorbitellipse
How to create a changing orbit from elliptical to planar and back?
I'm trying to create an object that rotates around the main camera, starting off on a planar orbit, then going elliptical, then back to planar. Essentially 'rotate the rotation'. Here is what I'm using, a great script from a while back:
using UnityEngine;
using System.Collections;
public class testRotate2 : MonoBehaviour {
GameObject cube;
public Transform center;
public Vector3 axis = Vector3.up;
public Vector3 desiredPosition;
public float radius = 2.0f;
public float radiusSpeed = 0.5f;
public float rotationSpeed = 80.0f;
void Start () {
cube = GameObject.FindWithTag("Cube");
center = cube.transform;
transform.position = (transform.position - center.position).normalized * radius + center.position;
radius = 2.0f;
}
void Update () {
transform.RotateAround (center.position, axis, rotationSpeed * Time.deltaTime);
desiredPosition = (transform.position - center.position).normalized * radius + center.position;
transform.position = Vector3.MoveTowards(transform.position, desiredPosition, Time.deltaTime * radiusSpeed);
}
}
It doesn't have to be perfect, just moving from a 'ring around your head' on the azimuthal plane gradually to the same thing but on the elevation/vertical plane, then back to flat, etc. Any ideas?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613022941im_/https://answers.unity.com/themes/thub/images/avi.jpg)