Hi everyone,
i am making a 2D game where the player can fly through space. When he gets near a planet he is supposed to get pulled towards the planet and at the same time spin around him.
I solved this by disabling the standart unity gravity and add a Pointeffector2D to the planet. This PointEffector gets activated when the Player enters a Collider placed around the planet. Then a script with the RotateAround function gets activated.
public class PlanetGravity : MonoBehaviour {
public float speed;
public Transform target;
private Vector3 zAxis = new Vector3(0, 0, 1);
void FixedUpdate()
{
transform.RotateAround(target.position, zAxis, speed);
}
}
That works pretty good but I have the problem that the player instantly starts rotating from the position he is at the moment. Like that the player is performing like a weird corner.
I want the player to get in the orbit smoothly but i have got no idea how to get a smooth transition.
I tried to use a delay but then the orbiting starts in some positions to late.
I would be very if someone could come up with an idea or code.