I am trying to keep a certain distance between two gameobects. However, the current way that I am attempting to do it spits out an error:
InvalidCastException: Cannot cast from source type to destination type.
orbit.Update () (at Assets/Standard Assets/Scripts/AI/orbit.js:17)
I am currently using this script:
#pragma strict
var otherObject : GameObject;
var distance;
function Start () {
}
function Update () {
distance = Vector3.Distance(this.transform.position, otherObject.transform.position);
if(distance !=50) {
Debug.Log(distance);
distance = 50;
transform.position = distance;
}
var somePos : Vector3 = otherObject.transform.position;
transform.RotateAround (somePos, Vector3.up, 20 * Time.deltaTime);
}
My question is this: Am I doing this right and if so how do I fix the error, or am I just keeping the distance horribly?