In-game flickering and unable to move camera vertically

After the course “Minimap Movement”, I was unable to move my camera vertically but was able to move it horizontally. I followed every step and watched the videos just in case I missed anything but I didn’t.

And after the course “Adding Polish”, I started getting a weird flickering effect. I am receiving flickers on both the client and the host sides.

Anyone encountered these problems during their time?

Please let me know how I can fix them.
Thanks!

Hi there, can you please share your camera controller script? This would help to figure out the first problem. For the second problem, is it possible to share a video showing this behaviour?

CameraController.cs

using Mirror;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class CameraController : NetworkBehaviour
{
    [SerializeField]
    private Transform playerCameraTransform = null;

    [SerializeField]
    private float speed = 20f;

    [SerializeField]
    private float screenBorderThickness = 10f;

    [SerializeField]
    private Vector2 screenXLimit = Vector2.zero;

    [SerializeField]
    private Vector2 screenZLimit = Vector2.zero;

    private Vector2 previousInput;
    private Controls controls;

    public override void OnStartAuthority()
    {
        playerCameraTransform.gameObject.SetActive(true);

        controls = new Controls();

        controls.Player.MoveCamera.performed += SetPreviousInput;

        controls.Player.MoveCamera.canceled += SetPreviousInput;

        controls.Enable();
    }

    [ClientCallback]
    private void Update()
    {
        if (!hasAuthority || !Application.isFocused)
        {
            return;
        }

        UpdateCameraPosition();
    }

    private void UpdateCameraPosition()
    {
        Vector3 pos = playerCameraTransform.position;

        if (previousInput == Vector2.zero)
        {
            Vector3 cursorMovement = Vector3.zero;

            Vector2 cursorPosition = Mouse.current.position.ReadValue();

            if (cursorPosition.y >= Screen.height - screenBorderThickness)
            {
                cursorMovement.z += 1;
            }
            else if (cursorPosition.y <= screenBorderThickness)
            {
                cursorMovement.z -= 1;
            }
            if (cursorPosition.x >= Screen.width - screenBorderThickness)
            {
                cursorMovement.x += 1;
            }
            else if (cursorPosition.x <= screenBorderThickness)
            {
                cursorMovement.x -= 1;
            }

            pos += cursorMovement.normalized * speed * Time.deltaTime;
        }
        else
        {
            pos += new Vector3(previousInput.x, 0f, previousInput.y) * speed * Time.deltaTime;
        }

        pos.x = Mathf.Clamp(pos.x, screenXLimit.x, screenXLimit.y);
        pos.z = Mathf.Clamp(pos.z, screenZLimit.x, screenZLimit.y);

        playerCameraTransform.position = pos;
    }

    private void SetPreviousInput(InputAction.CallbackContext ctx)
    {
        previousInput = ctx.ReadValue<Vector2>();
    }
}

I’ll send you the video for the second problem in a bit.

Edit:
2nd Problem

Yesterday when I was testing around, both my host and client screens were flickering but today, for some reason, even though I didn’t touch anything, when the client joins the host screen stops flickering and moves away vertically on it’s own as you can see in the video when I am unable to move the screen vertically myself with the camera input controls.

I am also unable to click on the minimap to change position of the camera.

P.S: Sorry for the music in the video.

Hi there, thanks for sending the video.

Are you running two instances of unity instead of an editor and a build? I would recommend running an editor and a build. This really looks like an issue with the input system. Also try running two builds and see what that does.

Is the flickering just visual? Or are the game objects deactivating or something?

Hi!
Thank you for your reply.

  1. No, I am only running an Editor and a build by going to the “Build and Run”.

  2. I also tried running two instances of the build. It is acting the same.
    Host issues before client joining > (Flickering, only horizontal camera movement, no minimap clicks, and camera teleportation)
    Host issues after client joining > (No more flickering, the camera moves automatically to the bottom-right end of the map and I can’t move the camera anymore not even horizontally and no minimap clicks and camera teleportation)
    Client issues when the client joins the game > (Flickering, only horizontal camera movement, no minimap clicks, and camera teleportation)

  3. I think the flickering is only visual as I can place buildings and create units without any problem.

All was working fine until I implemented the camera movement. After Camera Movement, I couldn’t move vertically. And when I implemented the Minimap, I was unable to click on the minimap. I triple-checked everything. I don’t know if I am missing something.
It’d be great if you help me out!

Okay, I have found the issue and it was this option (in the little red box) in the Player prefab’s Camera component that was turned on for some reason. After turning it off, the flickering stopped and I can now move my camera vertically.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms