im working on making a menu button for a UI. the script im using works exactly as it should, im just not really understanding how it works the way it does. the script is
using UnityEngine;
using System.Collections;
public class Button : MonoBehaviour {
public float spring;
private Vector3 restingPosition;
protected void ApplySpring() {
GetComponent<Rigidbody>().AddRelativeForce (-spring * (transform.localPosition - restingPosition));
}
// Use this for initialization
void Start () {
restingPosition = transform.localPosition;
}
// Update is called once per frame
void Update () {
ApplySpring ();
}
}
i have the rotations and the x and y positions constrained, the drag is set to 10, and the variable spring in the code above is set to 100. when you press the button it bobbles back and forth, basically doing what the springjoint component does. If i set spring to a positive value, the button just shoots forward and seems to never stop. So why does giving spring a negative value make this work like a springjoint?