My first post, so sorry if formatting is incorrect.
So I want to simulate tilt controls via the analog stick, and have the object in question sort of rotate around another. I tried Transform.RotateAround, but that’s a continual adding, which removes control
I also tried EulerAngles and saw my angle can be made to directly tie to the stick angle, but I’m not orbiting around the other object at all. Can someone help?
In other words, I just want to pivot around another GameObject, temporarily so no childing/parenting
My code:
public class Tilt : MonoBehaviour {
public GameObject parentee;
private Vector3 originalpos;
private Quaternion originalrot;
private Vector3 rotater;
public float timetoget;
float tx;
float tz;
// Use this for initialization
void Start () {
parentee = GameObject.FindGameObjectWithTag("Rotatee");
originalpos = this.transform.position;
originalrot = this.transform.rotation;
}
// Update is called once per frame
void FixedUpdate() {
Vector3 bobp;
bobp = this.transform.position;
Quaternion bobr;
bobr = this.transform.rotation;
//Debug.Log (this.transform.rotation.x);
float newHeadingx = Input.GetAxis("Vertical");
float newHeadingz = Input.GetAxis("Horizontal");
rotater.Set(parentee.transform.position.x, parentee.transform.position.y, parentee.transform.position.z);
if (Input.GetAxis("Vertical") != 0.1f || Input.GetAxis("Horizontal") != 0.1f)
{
if (0.19797f >= Mathf.Abs(this.transform.rotation.x) || 0.19797f >= Mathf.Abs(this.transform.rotation.z)) {
//transform.RotateAround(rotater, Vector3.right, 20 * Time.deltaTime * Input.GetAxis("Vertical"));
this.transform.eulerAngles = new Vector3((newHeadingx * 23f), 0, (newHeadingz * -23f));
tx = 0f;
}
}
if (Input.GetAxis("Vertical") == 0f && Input.GetAxis("Horizontal") == 0)
{
tx = 0.2f;
this.transform.position = Vector3.Lerp(bobp, originalpos, tx);
this.transform.rotation = Quaternion.Lerp(bobr, originalrot, tx);
}
}
}