Forum begins after the advertisement:


[part 8] Odd camera issue when ‘isWallJumping = true’

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [part 8] Odd camera issue when ‘isWallJumping = true’

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #15385
    James
    Level 2
    Participant
    Helpful?
    Up
    0
    ::

    Pretty much the title, I have a weird camera bug where the camera zooms out when isWallJumping is true.

    this happens everywhere, I don’t currently have any places with secret rooms and very few multi-box rooms.

    thanks for any help.

    gif of issue attached

    Wall Jump code:

    <code>[Header("Wall Jumping")]
    
        [SerializeField] private float wallSlidingSpeed = 2f;
        [SerializeField] private Transform wallCheck;
        [SerializeField] private LayerMask wallLayer;
        [SerializeField] private float wallJumpingDuration;
        [SerializeField] private Vector2 wallJumpingPower;
        float wallJumpingDirection;
        bool isWallSliding;
        bool isWallJumping;
        [Space(5)]
    </code>
    <code>if (pState.alive)
            {
                if(!isWallJumping)
                {
                    Flip();
                    Move();
                    Jump();
                }
    
                if(unlockedWallJump)
                {
                    WallSlide();
                    WallJump();
                }
                StartDash();
                Attack();
                Heal();
                CastSpell();
            }</code>
    <code>    private bool Walled()
        {
            return Physics2D.OverlapCircle(wallCheck.position, 0.2f, wallLayer);
        }
    
        void WallSlide()
        {
            if(Walled() && !Grounded() && xAxis != 0)
            {
                isWallSliding = true;
                Debug.Log("Wallsliding");
                rb.velocity = new Vector2(rb.velocity.x, Mathf.Clamp(rb.velocity.y, -wallSlidingSpeed, float.MaxValue));
            }
            else
            {
                isWallSliding = false;
            }
        }
    
        void WallJump()
        {
            if (isWallSliding)
            {
                isWallJumping = false;
                wallJumpingDirection = !pState.lookingRight ? 1 : -1;
    
                CancelInvoke(nameof(StopWallJumping));
            }
            if(Input.GetButtonDown("Jump") && isWallSliding)
            {
                isWallJumping = true;
                Debug.Log("Walljumping");
                rb.velocity = new Vector2(wallJumpingDirection * wallJumpingPower.x, wallJumpingPower.y);
    
                dashed = false;
                airJumpCounter = 0;
    
                pState.lookingRight = !pState.lookingRight;
                transform.eulerAngles = new Vector2(transform.eulerAngles.x, 180);
    
                Invoke(nameof(StopWallJumping), wallJumpingDuration);
    
            }
        }
    
        void StopWallJumping()
        {
            isWallJumping = false;
            transform.eulerAngles = new Vector2(transform.eulerAngles.x, 0);
        }
    }</code>

    And code for camera manager:

    <code>using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Cinemachine;
    
    public class CameraManager : MonoBehaviour
    {
        [SerializeField] CinemachineVirtualCamera[] allVirtualCameras;
    
        private CinemachineVirtualCamera currentCamera;
        private CinemachineFramingTransposer framingTransposer;
    
        [Header("Y Damping Settigns:")]
        [SerializeField] private float panAmount = 0.1f;
        [SerializeField] private float panTime = 0.2f;
        public float playerFallSpeedThreshold = -10;
        private float normalYDamp;
        public bool isLerpingYDamping;
        public bool hasLerpingYDamping;
    
        public static CameraManager Instance { get; private set; }
    
        private void Awake()
        {
            if (Instance == null)
            {
                Instance = this;
            }
    
            for (int i = 0; i < allVirtualCameras.Length; i++)
            {
                if (allVirtualCameras[i].enabled)
                {
                    currentCamera = allVirtualCameras[i];
    
                    framingTransposer = currentCamera.GetCinemachineComponent<CinemachineFramingTransposer>(); }
            }
    
            normalYDamp = framingTransposer.m_YDamping;
        }
    
        private void Start()
        {
            for (int i = 0; i < allVirtualCameras.Length; i++)
            {
                allVirtualCameras[i].Follow = PlayerController.Instance.transform;
            }
        }
    
        public void SwapCamera(CinemachineVirtualCamera _newCam)
        {
            currentCamera.enabled = false;
    
            currentCamera = _newCam;
    
            currentCamera.enabled = true;
    
        }
    
        public IEnumerator LerpYDamping(bool _isPlayerFalling)
        {
            isLerpingYDamping = true;
            //take start y damp amount
            float _startYDamp = framingTransposer.m_YDamping;
            float _endYDamp = 0;
            //determine end damp amount
            if (_isPlayerFalling)
            {
                _endYDamp = panAmount;
                hasLerpingYDamping = true;
            }
            else
            {
                _endYDamp = normalYDamp;
            }
            //Lerp pan amount
            float _timer = 0;
            while (_timer < panTime)
            {
                _timer += Time.deltaTime;
                float _lerpedPanAmount = Mathf.Lerp(_startYDamp, _endYDamp, (_timer / panTime));
                framingTransposer.m_YDamping = _lerpedPanAmount;
                yield return null;
            }
    
            isLerpingYDamping = false;
    
    
        }
    }
    </code>
    #15386
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    James, when you are wall jumping, check the Z coordinate of the player character on the Inspector. Is it changing?

    #15407
    James
    Level 2
    Participant
    Helpful?
    Up
    0
    ::

    Nope, the player character’s z remains the same but the main camera’s z moves from -9 to -11, as does the open room camera.

    edit: something that might be relevant is that if I manually set the y rotation top -180 or 180 (as the wall jump does) it pushes hte camera back aswell.

    #15412
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    There can be a variety of factors that are causing the Cinemachine to behave the way it is. Can you read through the first few results here and see if the issues they highlight (and the solutions proposed) apply to your situation?

    https://www.bing.com/search?pglt=41&q=cinemachine+camera+zooms+out+by+itself

    #15512
    James
    Level 2
    Participant
    Helpful?
    Up
    0
    ::

    hey Terr, I seem to have fixed it, apparently I have tracked object offset to 1 1 1 and the Z 1 for whatever reason pushed the camera back more when 180.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: