I found a simple pendulum script here. It works well for what I plan on using it for, except for where the pendulum starts swinging. Its a very basic script and I haven’t been able to find out how to change where the pendulum is starting to swing without messing up the timing. The pendulum is doing a 180 degree swing and I want it to start on the side rather than in the middle. Oh and don’t mind the bools, the pendulum is activated by another script. If I take off the /2.0f at the end of the Lerp the swinging will start in the right place but then the pendulum’s timing will be off and it won’t swing smoothly. Any help would be greatly appreciated.
using UnityEngine;
using System.Collections;
public class Pend : MonoBehaviour {
public float angle = 90.0f;
public float speed = 1.5f;
public bool activateR;
public bool activateL;
Quaternion qStart, qEnd;
private float startTime;
void Start () {
qStart = Quaternion.AngleAxis ( angle, Vector3.forward);
qEnd = Quaternion.AngleAxis (-angle, Vector3.forward);
}
void Update (){
if (activateR == true){
startTime += Time.deltaTime;
transform.rotation = Quaternion.Lerp (qStart, qEnd,(Mathf.Sin(startTime * speed) + 1.0f)/ 2.0f);
}
if(activateR == false && activateL == false){
resetTimer ();
}
}
void resetTimer(){
startTime = 0.0f;
}
}