I tried it out myself and I also had a tough time finding a way to Increase / Decrease Radius without changing the Speed.
I did manage to simply increase the Speed without changing the radius, which wasn't too difficult.
I don't know if it helps, but you'll be a step closer if you didn't have this yet :)
using UnityEngine;
using System.Collections;
public class GravityScript : MonoBehaviour
{
public Transform target;
public float SlerpSpeed = 3f; // Increasing SlerpSpeed, Orbit Radius Decreased, Orbit Duration Decreased
public float TranslationSpeed = 3f; // Increasing TranslationSpeed, Orbit Radius Increased, Orbit Duration Unchanged
public float OrbitSpeed = 5f; // Increasing OrbitSpeed, Orbit Radius Unchanged, Orbit Duration Increased
void Update()
{
Vector3 relativePos = target.position - transform.position;
Quaternion rotation = Quaternion.LookRotation(relativePos);
Quaternion current = transform.localRotation;
transform.localRotation = Quaternion.Slerp(current, rotation, SlerpSpeed * OrbitSpeed * Time.deltaTime);
transform.Translate(0, 0, TranslationSpeed * OrbitSpeed * Time.deltaTime);
}
}
Added some comments too, to maybe get better insight, good luck! :)
↧