I have been trying to find this out for quite a while now but stilling have the same problem. i have a gravity scripts that pulls the player towards the sphere and keeps him upright, but i cant seem to be able to make him move around the sphere.
here is a picture of how i’m thinking of it to end up as alt text
(Btw sorry for any miss spelling :))
Her are my gravity scipts
using UnityEngine; using System.Collections;
public class Player : MonoBehaviour {
//Gravity
public PlanetGravity gravity;
public Transform myTransform;
//
void Start () {
rigidbody2D.gravityScale = 0;
myTransform = transform;
}
void Update () {
gravity.Attract(myTransform);
}
void FixedUpdate () {
}
}
The planet
using UnityEngine;
using System.Collections;
public class PlanetGravity : MonoBehaviour {
public float gravity = -10;
public void Attract (Transform body)
{
Vector2 gravityUp = (body.position - transform.position).normalized;
Vector2 bodyUp = body.up;
body.rigidbody2D.AddForce(gravityUp * gravity);
Quaternion tragetRotatio = Quaternion.FromToRotation (bodyUp,gravityUp) * body.rotation;
body.rotation = Quaternion.Slerp (body.rotation,tragetRotatio, 50* Time.deltaTime);
}
}