Скрипт гравитации отталкивает объект вместо притягивания

Создал скрипт гравитации, но вместо того чтобы притягивать, он отталкивает объекты.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Planet : MonoBehaviour
{
    private HashSet<Rigidbody> affectedBodies = new HashSet<Rigidbody>();
    // Start is called before the first frame update
   private void Start()
    {
        
    }

    private void OnTriggerEnter(Collider other)
    {
       if (other.attachedRigidbody != null)
        {
            affectedBodies.Add(other.attachedRigidbody);
        }
    }
    private void OnTriggerExit(Collider other)
    {
        if (other.attachedRigidbody != null)
        {
            affectedBodies.Remove(other.attachedRigidbody);
        }
    }

    // Update is called once per frame
    private void Update()
    {
        foreach (Rigidbody body in affectedBodies)
        {
            Vector3 directionToPlanet = (transform.position - body.position).normalized;
            body.AddForce(directionToPlanet * 100);
        }
        
    }
}

Ответы (0 шт):