Game Creation Mastering Development

The ball should always move to the poles of the planet

I have a ball (player) that moves around the planet (also a ball, but of a larger size). The player must travel the planet passing circles from pole to pole. He has the ability to move left or right in order to avoid obstacles. How to realize the focus of the ball on the poles? I do not know how to make it so that the player can move but not bow out of the desired course.

I have a ball to which I apply force

And its child object to which the script is attached from which the direction of the force applied to the ball is taken

public class PlanetConstraint : MonoBehaviour
    [SerializeField] private Transform _targetPlanet;

    private void FixedUpdate()
        Quaternion rotation = Quaternion.FromToRotation(-transform.up, _targetPlanet.position - transform.position);
        transform.rotation = rotation * transform.rotation;

I think it’s worth somehow turning the child around the transform.up axis so that transform.forward is facing the pole.

More info:

Leave an answer

Your email address will not be published. Required fields are marked *