Entire screen drops down

Somewhere during this tutorial, can’t remember where, the screen drops down when I play the game. Like the whole thing descends suddenly. Pasting code for reference.

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

public class PlayerMovement : MonoBehaviour
{
[SerializeField] float runSpeed = 10f;

Vector2 moveInput;
Rigidbody2D myRigidbody;

void Start()
{
    myRigidbody = GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
    Run();
    FlipSprite();
}

void OnMove(InputValue value)
{
    moveInput = value.Get<Vector2>();
    Debug.Log(moveInput);
}

void Run()
{
    Vector2 playerVelocity = new Vector2 (moveInput.x * runSpeed, myRigidbody.velocity.y);
    myRigidbody.velocity = playerVelocity;
}

void FlipSprite()
{
    bool PlayerHasHorizontalSpeed = Mathf.Abs(myRigidbody.velocity.x) > Mathf.Epsilon;

    if (PlayerHasHorizontalSpeed) {
    transform.localScale = new Vector2 (Mathf.Sign(myRigidbody.velocity.x), 1f);
    }
}

}

Hi,

What do you mean by “the screen drops down”? When exactly does that happen when you play the game? Please elaborate further on the problem.

Gravity pulls all the screen contents down.

In this case, check if a Rigidbody2D component is attached to the ground or other game objects that are not supposed to be affected by gravity. If they require a Rigidbody2D component for some reason, set the Body Type to “Static”.

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

Privacy & Terms