Forum rules - please read before posting.

Rotate camera around a circle

edited May 2020 in Technical Q&A

Hello guys!

I hope you can help me with this. I'm making a 2D game with direct control, and I'd like to make a scene, where player walks on top of a circle, and camera would follow him. The idea is, that this big circle is this never-ending scene, that would in a sense roll beneath player's feet. I hope you get what I mean, I want to make a scene, where there's no distinct start or end point. Something like Super Mario Galaxy but with a circle instead of a planet. I can't figure out how to approach this. Is it possible to create a camera, which follows the player on some kind of axis, or is there a simple solution for this?

Comments

  • As this is a very visual issue, can you share a screenshot or sketch to make sure we're on the same page?

    This sounds like it's not just about having the camera rotate, but also the player too, right?

    The provided 2D camera assumes "up is up", but it's possible to make use of custom camera scripts if you can provide them. In fact, since the GameCamera2D doesn't affect rotation at all, you could probably get by with attaching a script that controls its rotation - and still have the GameCamera2D move with the Player.

    You'd first want to make sure that the camera's Projection is set to Orthographic, though, since the camera won't physically move otherwise.

    It'll also be a lot easier if the centre of your circle is in the centre of the scene - so that you can just use the camera's X/Y position to update its up direction. Something like this:

    using UnityEngine;
    
    public class RotateAroundOrigin : MonoBehaviour
    {
    
        private void Update ()
        {
            Vector3 direction = new Vector3 (transform.position.x, transform.position.y, 0f);
            transform.up = direction;
        }
    
    }
    

    Attaching that to your Player's Sprite Child should cause them to rotate, too.

  • Thanks! I'll try this :)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.