You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

63 lines
1.5 KiB

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class gravityWell : MonoBehaviour {
public float wellMass;
public int gravConstPow;
public GameObject[] targets;
//public float minDistance;
//public float bufferZone;
//public float bufferDampner;
public float clampVelo;
public float maxVelo;
public float moveSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
foreach (GameObject target in targets) {
/*target.rigidbody.AddForce( calcGrav (target));
target.rigidbody.velocity = Vector3.ClampMagnitude(target.rigidbody.velocity, clampVelo);
Debug.Log(target.rigidbody.velocity.magnitude);*/
float step = moveSpeed * Time.deltaTime;
target.transform.position = Vector3.MoveTowards(target.transform.position,transform.position, step);
}
}
private Vector3 calcGrav(GameObject target){
double GRAVCONSTANT = 6.673f * Mathf.Pow (10, gravConstPow);
Vector3 distance = this.transform.position - target.transform.position;
float mag = distance.magnitude;
distance /= mag;
float gravityForce = (target.GetComponent<Rigidbody>().mass * wellMass * (float)GRAVCONSTANT) / (mag * mag);
//if (minDistance > mag)
// return (Vector3.zero);
//else if (bufferZone > mag)
// return (-(distance * gravityForce)/bufferDampner);
//else
Debug.Log ((distance * gravityForce).magnitude);
if ((distance * gravityForce).magnitude > maxVelo)
return (Vector3.zero);
else
return (distance * gravityForce);
}
}