Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Gravity : MonoBehaviour
- {
- public float mu = 1f;//Гравитационная постоянная G
- private void OnTriggerStay(Collider col)
- {
- //Квадрат расстояния между телами
- double sqrDistance = (transform.position - col.transform.position).sqrMagnitude;
- col.attachedRigidbody.AddForce(
- (transform.position - col.transform.position).normalized * (mu / sqrDistance),
- ForceMode.Force
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement