Trying to set a camera movement with colliders

Hi, first post ever, I’ll try my best to make it comprehensible (I see after the fact that it is quite a long post, sorry…).
I’m a perfect newbee and after following some tutorials I thought that I could experiment and learn a bit by working on a small idea I had for my own amusement, while I use chatGPT to help me with syntax and proper actions (methods ?) to call.

I am trying to make a good old fashion point click style game (Monkey Island and all).
I have already made the very basics artworks that I need to test some first codes and functionalities.
Right now, my worflow is the following :
_I prepare on paper the idea of what I want to do
_I have everything set in Unity as I “think” it should be
_I start creating the basic of my scripts.
_Make a thing that work but find a problem that I don’t undestand
_Proceed to wish I have always been dead

So about the game itself :
I have made the basics of my very first scene/room and a first sprite of my main character, here it is :


You can already see that there is a camera (16/9) in a wide background, and little footprints on the ground.

Here is my hierarchy :

_“bedRoomBackground” is my background
_“bedRoomOverLayer” is the big dark grey pillar in the middle (it’s a wall separation)
_“colliderRight” and “colliderLeft” are the respective little footprints on the floor
_“Character” who has the sprite of the character and is a children of the “Character Pivot” (I use it for setting the anchor point of the character and the script for the position)
_“MainCamera” who is the camera, children of controllerCamera (I like to keep control of the children independently)

Inside “colliderRight/Left” and “Character” I have a Box Collider 2D, with the sizes and positions I want them to have :

Now The idea is :
Make a dolly shoot from one side of the room to the other. The dolly is activated by one click on one of the footprints and when the character enters the space where his collider and the collider of the footprints intersect each other.

So about the steps I think it should take :
0_By default the footprints are deactivated (to prevent the dolly movement to happen just if the character randomly walk on the collider)
1_I click on one of the desired footprints > activate the collider
2_The character goes where the click happens, making his collider overlaping with the footprints collider (he already has the proper code to go to where the click happens)
3_When both the collider are overlaping the camera movement starts and go to the other side of the room
Some exceptions:
Beeing able to reverse the camera movement in case of an error.
ex :If I click on the right collider by accident (activating the camera movement) and want to reverse it fast by clicking on the left collider or somewhere else (while the camera is still dollying), it should stops the movement and come back where it were.

So, right now, the code I want to make this happens is on one script who is on both of the colliderRight/Left. The idea is to have these colliders making the entire movement happens to their own opposite side.
I am at the first step : Click to activate the collider.
Here is the code I have right now :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ControllerDollyCam : MonoBehaviour
{
    //All the slots I need to link in Unity I can think of for now
    public GameObject controllerCamera;
    public BoxCollider2D character;
    public BoxCollider2D colliderRight;
    public BoxCollider2D colliderLeft;
    public Vector3 positionDollyRight;
    public Vector3 positionDollyLeft;
    //Some private bool I wanted to use at first but chat gpt decided to change that (still there in case)
    private bool activateRightCollider = false;
    private bool activateLeftCollider = false;

    //Activate one footprint collider and deactivate the other
    private void OnMouseDown ()
    {
        Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        if (colliderRight && colliderRight.OverlapPoint(mousePosition))
        {  
            //Activate the collider I click on
            colliderRight.enabled = true;
            Debug.Log("Right collider activated");
            //Deactivate the other collider in case the character walk on it afterwards
            colliderLeft.enabled = false;
            Debug.Log("Left collider deactivated");

        }
        //Same but for the other collider
        else if (colliderLeft && colliderLeft.OverlapPoint(mousePosition))
        {
            colliderRight.enabled = false;
            Debug.Log("Right collider deactivated");
            colliderLeft.enabled = true;
            Debug.Log("Left collider activated");
        }
    }

   
    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
 
    }
}

Here is what it looks like in unity for one of the collider in the inspector :

The problem I have now :
When I click on one of the collider (no matter which one), I can see in the console that it is working properly, however if I click on the second collider afterwards, nothing happens.

My own commentary :
_I think it is because of the lines “colliderRight.enabled = false;” “colliderLeft.enabled = false;”. It sets their status as false and inactive indefinitely. I don’t know how to implement this correctly.
_I think I should use a “switch { case }” instead of an “if{} else {}” but I am not sure
_I wanted to use the “private bool activeRight/leftCollider = false” to link to the proper colliders so I can switc hthem on/off, but chat GPT corrected it, is it a mistake or did i really didn’t needed it ?

There it is for now, should I rework it entirely or is it simpler than that ?

I hope it wasn’t too long and that everything is here.
Thanks for your reponses and good night (it is 11pm here)!

Camera stuff is pretty tricky… you may wish to consider using Cinemachine from the Unity Package Manager.

There’s even a dedicated forum: Unity Engine - Unity Discussions

If you’re having trouble with the flow of your code, then it is …

Time to start debugging! Here is how you can begin your exciting new debugging adventures:

You must find a way to get the information you need in order to reason about what the problem is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

What is often happening in these cases is one of the following:

  • the code you think is executing is not actually executing at all
  • the code is executing far EARLIER or LATER than you think
  • the code is executing far LESS OFTEN than you think
  • the code is executing far MORE OFTEN than you think
  • the code is executing on another GameObject than you think it is
  • you’re getting an error or warning and you haven’t noticed it in the console window

To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

  • is this code even running? which parts are running? how often does it run? what order does it run in?
  • what are the names of the GameObjects or Components involved?
  • what are the values of the variables involved? Are they initialized? Are the values reasonable?
  • are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

Knowing this information will help you reason about the behavior you are seeing.

You can also supply a second argument to Debug.Log() and when you click the message, it will highlight the object in scene, such as Debug.Log("Problem!",this);

If your problem would benefit from in-scene or in-game visualization, Debug.DrawRay() or Debug.DrawLine() can help you visualize things like rays (used in raycasting) or distances.

You can also call Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc.

You can also call GameObject.CreatePrimitive() to emplace debug-marker-ish objects in the scene at runtime.

You could also just display various important quantities in UI Text elements to watch them change as you play the game.

Visit Google for how to see console output from builds. If you are running a mobile device you can also view the console output. Google for how on your particular mobile target, such as this answer or iOS: How To - Capturing Device Logs on iOS or this answer for Android: How To - Capturing Device Logs on Android

If you are working in VR, it might be useful to make your on onscreen log output, or integrate one from the asset store, so you can see what is happening as you operate your software.

Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

Here’s an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

“When in doubt, print it out!™” - Kurt Dekker (and many others)

Note: the print() function is an alias for Debug.Log() provided by the MonoBehaviour class.

Thank’s man ! I’ll definitly check those links, and research a bit more on what are all those different Debug options !
This Cinemachine stuff look promising also. I think it may be what I need (at first glance). Thank’s for the tip !
I guess I have more reading to do now :smile:. I guess I’ll be back.