0
using System.Collections.Generic;
using UnityEngine;

public class TouchMovement : MonoBehaviour
{
    // 2d smooth horizontal drag system for mobile and mouse
    public float dragSpeed = 2;
    private Vector3 dragOrigin;
    
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            dragOrigin = Input.mousePosition;
            return;
        }
    
        if (!Input.GetMouseButton(0)) return;
    
        Vector3 pos = Camera.main.ScreenToViewportPoint(Input.mousePosition - dragOrigin);
        Vector3 move = new Vector3(pos.x *- dragSpeed, 0, 0);
    
        transform.Translate(move, Space.World);  
    }
}

this is my camera movement in my cinemachine virutal camera put when i add Cinemachine Confiner 2D and set a limtis to it , the cinemachine brain goes beyond it limtis but the camera stays the (X) value , so it my problem is when i try to go to the edge of the limtis it keeps on and goes beyond the mean the virtual camera but so when it try to get back of the limits i wait the virtual camera Wait for it to catch up .

Hany.
  • 3
  • 2
  • I have the same problem. How did you fix it? – HamsterWithPitchfork Oct 30 '22 at 18:01
  • Set The cinemachine transform.position to = camera.transform.position – Hany. Oct 31 '22 at 10:02
  • Could you please elaborate? At which point do you set the cinemachine transform to be the same as camera's transform? I am moving my cinemachine transform based on user input. So real camera is confined to the boundary, but vcam keeps moving with the input. – HamsterWithPitchfork Nov 01 '22 at 11:16
  • i setted it in the update function when the camera position != Cinemachine position , if you got any more questions you can ask , sorry i couldn't elaborate this more – Hany. Nov 02 '22 at 12:35

0 Answers0