Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FauxGravityAttractor : MonoBehaviour
public float gravity = -10f;
public float slerpSpeed = 50f;
public void Attract (Transform body)
Vector3 gravityUp = (body.position - transform.position).normalized;
Vector3 bodyUp = body.up;
body.GetComponent<Rigidbody>().AddForce(gravityUp * gravity);
Quaternion targetRotation = Quaternion.FromToRotation(bodyUp, gravityUp) * body.rotation;
body.rotation = Quaternion.Slerp(body.rotation, targetRotation, slerpSpeed * Time.deltaTime);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment