SHARE
TWEET

Gravity.cs

a guest May 16th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Gravity : MonoBehaviour
  6. {
  7.     public float mu = 1f;//Гравитационная постоянная G
  8.     private void OnTriggerStay(Collider col)
  9.     {
  10.         //Квадрат расстояния между телами
  11.         double sqrDistance = (transform.position - col.transform.position).sqrMagnitude;
  12.         col.attachedRigidbody.AddForce(
  13.             (transform.position - col.transform.position).normalized * (mu / sqrDistance),
  14.             ForceMode.Force
  15.             );
  16.     }
  17. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top