forked from absh8989/DET-SoulSphere
24 lines
927 B
C#
24 lines
927 B
C#
using UnityEngine;
|
|
[RequireComponent(typeof(SphereCollider))]
|
|
public class Singularity : MonoBehaviour
|
|
{
|
|
//This is the main script which pulls the objects nearby
|
|
[SerializeField] public float GRAVITY_PULL = 100f;
|
|
public static float m_GravityRadius = 1f;
|
|
|
|
void Awake() {
|
|
m_GravityRadius = GetComponent<SphereCollider>().radius;
|
|
|
|
if(GetComponent<SphereCollider>()){
|
|
GetComponent<SphereCollider>().isTrigger = true;
|
|
}
|
|
}
|
|
|
|
void OnTriggerStay (Collider other) {
|
|
if(other.attachedRigidbody && other.GetComponent<SingularityPullable>()) {
|
|
float gravityIntensity = Vector3.Distance(transform.position, other.transform.position) / m_GravityRadius;
|
|
other.attachedRigidbody.AddForce((transform.position - other.transform.position) * gravityIntensity * other.attachedRigidbody.mass * GRAVITY_PULL * Time.smoothDeltaTime);
|
|
}
|
|
}
|
|
}
|