# Movement around a 2D circle

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);
}

}

do not use position use local position and calculate forward

maybe something like Vector3 newDirection = transform.forward - NextSpot.Normal

If you really want to do it like a circle then calculate for each step a angle then Calculate your current Vector3 starting from the center with sin and cos and your next with these two you can find the vector that is approx… your direction