c# – Unity – adding camera constraint to prevent the player from seeing beyond the scene

Like the title says, I’m after some kind of constraint for the camera to prevent the player from seeing beyond the scene and seeing the Skybox. I came across the code to add a Mathf.Clamp, but I can’t get it to work.
I’m currently trying to make a 2.5D platformer in which the camera follows the player (ahead), which leads to seeing beyond the scene to the far left and right. I already have an invisible wall in place to prevent the player from falling off, but I would love to also clamp the camera from going any further.

This is the script I have at the moment:

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

public class CameraController : MonoBehaviour
    (SerializeField) GameObject player = null;
    (SerializeField) (Range(0.1f, 2f)) float followAhead = 2f;
    (SerializeField) (Range(0.1f, 2f)) float smoothing = 1f;

    //public PlayerController playerController;

    private float minPosition = -9.37f;
    private float maxPosition = 4.68f;
    private Vector3 cameraClamp;

    const float m_minY = 2f;
    Vector3 targetPosition;
    Vector3 cameraOffset;

    void Start()
        cameraOffset = transform.position - player.transform.position;

    void Update()
        targetPosition = (player.transform.position + (player.transform.forward * followAhead)) + cameraOffset;
        //smoothedForward = Vector3.MoveTowards(smoothedForward, playerController.GetTravelDirection(), 0.5f * Time.deltaTime);
        //targetPosition = (player.transform.position + (smoothedForward * followAhead));
        //transform.position = player.transform.position + cameraOffset;
        targetPosition.y = Mathf.Min(targetPosition.y, m_minY);
        transform.position = Vector3.Lerp(transform.position, targetPosition, smoothing * Time.deltaTime);
        cameraClamp.x = Mathf.Clamp(transform.position.x, -9.37f, 4.68f);

opengl – How do I make the 3rd person camera follow the space ship in my Space Shooter game?

I am making a 3D space shooter game using OpenGL and Bullet Physics. I am having a hard time with the 3rd person Camera though. If you take a look at the video above you can see that the camera follows the spaceship rotating on the X axis without a problem and rotating on Z axis also without a problem when the spaceship is is oriented towards the horizon and parallel to the ground. When I roll to the right and move the spaceship up I am totally losing it from the camera. The code for my camera is as follows:

float CalculateHorizontalDistance() {
    if (!mpPlayer) return 0.f;

    return distanceFromPlayer * glm::cos(glm::radians(-UpAngle));

float CalculateVerticalDistance() {
    if (!mpPlayer) return 0.f;

    return distanceFromPlayer * glm::sin(glm::radians(-UpAngle));

void calculateCameraPosition(float horizDistance, float verticDistance)
    if (!mpPlayer) return;

    glm::vec3 playerFront = mpPlayer->GetFront();
    glm::vec3 playerPos = mpPlayer->GetPosition();

    Position = playerPos + ((-playerFront) * distanceFromPlayer);

    UpAngle = 180.f - mpPlayer->GetRoll();
    //RightAngle = -mpPlayer->GetPitch();
    RollAngle =  mpPlayer->GetYaw() - 180.f;

    //float theta = mpPlayer->GetRotationY() + angleAroundPlayer;
    //float offsetX = horizDistance * glm::sin(glm::radians(theta));
    //float offsetZ = horizDistance * glm::cos(glm::radians(theta));

    //Position.x = mpPlayer->GetPosition().x - offsetX;
    //Position.y = mpPlayer->GetPosition().y + verticDistance;
    //Position.z = mpPlayer->GetPosition().z - offsetZ;

The above code is used to calculate the position and rotation of the camera. The commented out code was used to calculate the position based on trigonometrical calculations for the x and z sides of the triangle created from the camera position to the player position. This didn’t work right because I could never set the camera behind the spaceship, only the position worked well.

On the non-commented out code I use as a camera position the player position – back vector * offset. This works fine for the simple purpose that the camera is always on the back side of the spaceship. I also update pitch and roll which works almost fine and here is where I need help mostly to get this right. I also never update the yaw of the camera.

This is how I get yaw, pitch and roll from Bullet Physics rigid body of the player (spaceship):

btScalar yaw;
btScalar pitch;
btScalar roll;
body->getCenterOfMassTransform().getBasis().getEulerZYX(yaw, pitch, roll, 1);

The following code is how the orientation of the camera is calculated :

void updateCameraVectors()
    // Yaw
    glm::quat aroundY = glm::angleAxis(glm::radians(-RightAngle), glm::vec3(0, 1, 0));

    // Pitch
    glm::quat aroundX = glm::angleAxis(glm::radians(UpAngle), glm::vec3(1, 0, 0));

    // Roll
    glm::quat aroundZ = glm::angleAxis(glm::radians(RollAngle), glm::vec3(0, 0, 1));

    Orientation = aroundY * aroundX * aroundZ;

    glm::quat qF = Orientation * glm::quat(0, 0, 0, -1) * glm::conjugate(Orientation);
    Front = { qF.x, qF.y, qF.z };
    Right = glm::normalize(glm::cross(Front, WorldUp));
    Up = glm::normalize(glm::cross(Right, Front));

and lastly how the view matrix of the camera is calculated:

glm::mat4 GetViewMatrix()
    // You should know the camera move reversely relative to the user input.
    // That's the point of Graphics Camera

    glm::quat reverseOrient = glm::conjugate(Orientation);
    glm::mat4 rot = glm::mat4_cast(reverseOrient);
    glm::mat4 translation = glm::translate(glm::mat4(1.0), -Position);

    return rot * translation;

Can someone help me fix the rotational problems that I am facing? I am open to modify also the Camera Class to make it work better with Bullet’s quaternions instead of the Euler’s angles that I am trying to use. Any code or ideas are very welcomed. Thank you for reading through.

adb – Clean camera application without on-screen controls

I use ADB to stream my phone screen to my laptop over USB. I would like to extend this method to stream the camera output to my laptop. To do that, I connect my phone over ADB, start screencast, and open the camera app. I get the camera output on my laptop with no issues, but I also see the on-screen buttons such as shutter, settings, gallery etc. I tried magnifying glass and mirror apps but all the apps I checked do have the controls. So, the question is – Is there a camera app for Android that does not show on-screen controls? Alternatively, is there a FOSS app that can stream camera output to laptop (preferably, Linux or Mac) over ADB? Thanks!

P.S.: I tried IP webcam applications but unlike ADB they all have significant delay.

field of view – What is the focal length on your typical cell phone camera?

Focal length does not change with sensor sizes – what actually changes is the field of view:

FOV (°) = 2 * arctan ( d (mm) / (2 * f (mm)) )

FOV is our field of view in degrees, d is one of the dimensions of the sensor (for diagonal, it is d = √(h² + w²) ) and f is the focal length in millimeters.

In very simple terms, a smaller sensors sees a smaller portion of the lens’s projection – e.g. a APS-C sensor does not fill out a 35mm lens’s image circle, so it cannot see the outer portions (which relate to the outer regions of the frame) and therefore, the field of view is narrower than it would be with a full frame camera.

When we talk about crop-factors, what we really are talking about is the change in field of view by a smaller sensor: The reference is a full frame sensor, which is 36*24mm. Therefore, a 10mm lens on an APS-C camera is still a 10mm lens – it just happens that it offers the same FOV as a 15mm lens would on a full frame camera.

The same of course is true for smartphones – unfortunately, the smartphone market is constantly and rapidly changing, and manufacturers usually do not state focal length or sensor size in their marketing texts, so research is needed on a per-phone-basis (or so I think).

A (at this moment) recent iPhone X offers an equivalent-to-28mm lens and an equivalent-to-52mm lens, the Samsung Galaxy S9+ offers 26/52mm, the OnePlus 6 offers 25mm, the Huawei P20 offers 27mm/80mm, the Nokia 6.1 offers 27mm,…

So it seems we can conclude that 26-28mm (equivalent) are a standard in Q3/2018.

stock android – How to install Google Camera on Nokia TA-1053

My phone Nokia TA-1053 is almost stock android with a couple of apps from them here and there. I really dislike their camera app. So, I tried to install Google Camera(since all other apps are from Google).

Now Google Camera app is not available in Play Store(at least for my phone). So I tried to side-load it from Apkmirror. My phone’s android version in 9 and it supports API 28.

I downloaded the apk, installed it and when I was trying to open it, the app just won’t open. It instantly shuts down the app and shows error messages. What should I do?

Player Camera Shaking when Running Into Wall in Unity

I’ve been working on a 2D RPG game in Unity, and for some reason, whenever my character runs into a wall, the camera begins to shake violently. I have a RigidBody2D and a BoxCollider2D connected to him and a TilemapCollider connected to my Tilemap. The RigidBody component is Dynamic with a gravity scale of 0 (because it’s a top-down game). Also, the camera is a child of the player. Here’s the script to my character controller:

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

public class PlayerController : MonoBehaviour
    // Variable for the player speed and animation
    float speed = 2f;
    private Animator animator;
    private Vector3 change;
    // Called before the first frame is loaded
    void Start()
        // Gets animator component
        animator = GetComponent<Animator>();
    // Update is called once per frame
    void Update()
        // Detects change in the player's coordinates
        change = Vector2.zero;
        change.x = Input.GetAxisRaw("Horizontal");
        change.y = Input.GetAxisRaw("Vertical");
        if (change != Vector3.zero)
            // Detects whether the player's animation should play or not
            animator.SetFloat("moveX", change.x);
            animator.SetFloat("moveY", change.y);
            animator.SetBool("moving", true);

            animator.SetBool("moving", false);

    void MoveCharacter()
        //  Allows movement on the X axis and calculations to allow the player to move
        if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
            transform.Translate(Vector2.right * speed * Time.deltaTime);
        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
            transform.Translate(-Vector2.right * speed * Time.deltaTime);

        // Allows movement on the Y axis
        if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
            transform.Translate(Vector2.up * speed * Time.deltaTime);
        if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
            transform.Translate(-Vector2.up * speed * Time.deltaTime);

A Disc Camera likely to be usable in 2021

I have some Disc Film in the fridge that I would like to use, that I got from a film lot.

It seems unlikely that anything amazing will come out of it, but experimenting is part of my process and some recent results look really cool.

I found a lab that processes it, but I don’t own a Disc camera. They seem to cost a dime a dozen on second-hand marketplaces, however, I recall from using one in the past that the batteries are usually not removable by the user, to save space and make a thin camera (they are welded inside the body) – and therefore, batteries from this period might have ran out of juice or become damaged if I just bought any such model.

Given that over 30 different manufacturers made cameras that use disc film, I wonder if some of them were smart enough to design them to use regular, removable batteries.

These types of cameras are very under-documented across the internet.

Are there Disc film cameras that use regular removable batteries?

android 10 – Camera doesn’t save with new SD card and how to decrypt files from old SD card

it seems I had a bad idea yesterday. I got a new SD card for my Fairphone 3+ (running Fairphone OS/Android 10). There was already an SD card inserted I assumed not to be in use. So I turned off the phone, exchanged the cards, booted the device and when asked to extend the phones memory I confirmed that.

Now I have two problems:

  • I’m missing a couple of pictures.

    I wondered if these were on the old (luckily only 8GB) SD card and recognized that there are two partitions on it: android_meta and android_expand. As far as I learned, this means the SD card also was used as phone memory extension and thus encrypted. And the posts on Android Enthusiasts read like the phone has only one encryption key and won’t recognize the old SD card anymore.

  • The Camera can’t save pictures anymore.

    Whenever I take a photo I’m able to immediately open it by tapping its preview. Then I see a black picture, I’m told its size is 0 bytes and it’s located in /storage/emulated/0/DCIM/Camera. Using the cx File Explorer I’m able to open that directory, but it’s empty. And I’m not able to create files there.

    Using the ADB shell I was able to ls -la /storage the directory and got this:

    total 7
    drwxr-xr-x  4 root root        80 2020-12-21 06:52 .
    drwxr-xr-x 21 root root      4096 2009-01-01 01:00 ..
    drwx--x--x  4 root sdcard_rw 3488 2021-01-12 21:38 emulated
    drwxr-xr-x  2 root root        60 1970-01-01 01:00 self

    So only root is able to write in /storage/emulated. BTW: “total 7”?

Currently I’m trying to find out the following:

  • is it possible to decrypt the pictures on the old SD card? Would be fine for me if it meant some work 🙂
  • is the encryption key for the old SD card still on the phone or could I reset the phone without making things worse regarding the old encrypted SD card?
  • is the phone in a bad state?
    • The Camera doesn’t save pictures.
    • All other apps seem to work as expected.
    • The SD card overview in the Memory settings tell me there are apps on the new SD card (about 5GB). But when I tap the App category to get all apps listed, the list is empty.
    • When I eject the SD card, a couple of apps start, but only show a blank canvas.
  • if the phone is in a bad state: could this easily be fixed? If yes, how?

Would be great to get some hints. Thank you very much in advance.

digital – A Camera that takes real photos without manipulation like old analog cameras

In modern digital cameras there are many settings which are applied automatically to the photos. And it does not always result in good ways. Recently I saw two photos of the same face one from a old analogue camera and the other a digital one.

The photos were considerably different and the one from analogue was much more close to the real face in every aspect.

So this is my question as I am not a pro in camera market:

Is there any model of digital cameras in the market in 2021 that takes photo like analogue cameras without manipulation and artificial improvements?