#Help

1 messages · Page 1 of 1 (latest)

gentle remnant
#

So in short

#

I want the camera to stop when it gets to the end of the screen (set by me), above is the code, but it doesn't work

#

video in a sec

still reef
#

wait i will have a look

still reef
#

sorry but this makes no sense

#

so there are a few problems:

#
  • the camera doesnt even have an collider so OnCollsion Events can't be triggered
#
  • the bounds collider is set to trigger so that won't cause the Collision Event either even if the camera had an collider
#

i would recommend to use cinemachine for your camera system

#

here is an good and short tutorial

#

after that you can create an empty gameobject attach your old movement script to it and set the cinemachine target to that gameobject

#

and also remove the collision part since cinemachine does boundaries and the rest

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class CameraMovement : MonoBehaviour
{
    public float mDelta = 10; // Pixels. The width border at the edge in which the movement work
    public float mSpeed = 3.0f; // Scale. Speed of the movement
 
 
    private Vector3 mForwardDirection; // What direction does our camera start looking at
    private Vector3 mRightDirection; // The inital "right" of the camera
    //private Vector3 mUpDirection : float mSpeed { get => mSpeed; set => mSpeed = value; }
 
    //Vector3; // The inital "up" of the camera
 
    void Start()
    {
        mForwardDirection = transform.forward;
        mRightDirection = transform.right;
        //mUpDirection = transform.up;
    }
 
    void Update()
    {
 
        // Check if on the right edge
        if (Input.mousePosition.x >= Screen.width - mDelta)
        {
            // Move the camera
            transform.position += mRightDirection * Time.deltaTime * mSpeed;
        }
 
 
        if (Input.mousePosition.x <= 0 + mDelta)
        {
            // Move the camera
            transform.position -= mRightDirection * Time.deltaTime * mSpeed;
        }
 
        Debug.Log(isTouching);
    }
}