how can i an exit script to this script so instead of stoping objects completely on exit it will like slowly come to a stop rather than instantly? public bool useFixedDirection;
public Vector3 pullDirection;
public float timescale = 1;
public float pullSpeed;
public float radius;
private SphereCollider _col;
private Vector3 _enterDirection;
private void Start()
{
_col = GetComponent<SphereCollider>();
}
private void Update()
{
_col.radius = radius;
Time.timeScale = timescale;
}
private void OnTriggerEnter(Collider other)
{
_enterDirection = (transform.position - other.transform.position).normalized;
}
private void OnTriggerStay(Collider other)
{
float _dist = Vector3.Distance(other.transform.position, transform.position);
float _ratio = _dist / radius;
if (useFixedDirection)
other.attachedRigidbody.AddForce(pullDirection * pullSpeed * _ratio);
else
other.attachedRigidbody.AddForce(_enterDirection * pullSpeed * _ratio);
}
private void OnTriggerExit(Collider other)
{
other.attachedRigidbody.velocity = Vector3.zero;
}
}
@Kilsnus