Advertisement
Guest User

Gravity.cs

a guest
May 16th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement