I’m a beginner in Unity, and I’m having difficulty confining my Cinemachine.
Its a pretty simple requirement, when i reach the end of the screen on the right or left, i dont want to the camera to keep moving.
additionally, i also dont want it to show some part of the bottom.
I did the following:
Created an empty object and added a Box collider - made it fit my entire level, its surrounding it.
Added an Extension to Cinemachine called “Cinemachine Confiner”:
I actually saw that warning in the beginning, but when i used a polygon a lot of things didnt work, and the clamp didnt seem to work either, so i tried other Colliders and used the most basic one which is a box (since its a 2D platformer), and when that didnt work either i decided to use the forums… forgetting about that warning.
Using a polygon it does indeed clamp it to the borders i’ve made (a box), and i noticed something’s wrong with the physics so i just created another layer for the Confiner and took everything off from that new layer in the Physics 2D.
is that the correct approach if you have a collider within a collider? (my player is within the polygon, if its on the same layer).
I also had the same problem with the physics, and I never thought to add the confiner to the player layer. Thanks for helping out, I couldn’t find any video on this so this really helped me
I tired to use BoxCollider2D used by the CompositeCollider2D, but it still warns that “CompositeCollider2D geometry type must be Polygone”.
I’m wondering why it must be exactly Polygon? I mean what is wrong with a rectangle shape? In my case, I need to change the confiner at runtime, and it seems to me to be more efficient to use simple forms like boxes, so why is a simple BoxCollider2D not supported and must have more than 4 vertices?
I am trying to use my bounding shape Cam Boundry but the confiner won’t confine to it after I load a level and go back to the previous level. Any idea as to why it won’t confine? Could it be because the boundary isn’t in the DontDestroyOnLoad. How could I go about fixing this?
Fix:
I was able to write a script that got the gameobjects polygon collider component and use it for the confiner.
This is my code for people with similar issues.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
public class DirectingCamBoundry : MonoBehaviour
{
private GameObject BoundryEmptyObject;
public PolygonCollider2D BoundryShape;
public CinemachineConfiner confiner;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (GameObject.FindGameObjectWithTag(“Boundry”) == null)
{
confiner.m_BoundingShape2D = null;
}
If anyone comes looking for this as of Cinemachine 3.1.1 (maybe a bit earlier) you can just use a BoxCollider2D without using a composite collider on top.