Player is still falling slow

This is my player movement script:

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

public class PlayerMovement : MonoBehaviour
{
    Vector2 moveInput;
    Rigidbody2D myRigidbody;
    [SerializeField] float runSpeed;
    
    void Start()
    {
        myRigidbody = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
        Run();
    }
    void OnMove(InputValue value)
    {
        moveInput = value.Get<Vector2>();
        Debug.Log("moving");
    }
    void Run()
    {
        Vector2 playerVelocity = new Vector2(moveInput.x * runSpeed, myRigidbody.velocity.y);
        myRigidbody.velocity = playerVelocity;
    }
}

But the player is still behaving very weirdly when falling. It is not following gravity… Unless gravity is the gravity of a small asteroid.

EDIT: The gravity setting is the same as it ever was. -9.81, the default value. Altering it does nothing
EDIT 2: The instance and the prefab have Gravity scale set to 1.

How about trying FixedUpdate() instead of Update(). Physics should be done in FixedUpdate()

Nope. No change

I tested the code and it seems fine. What exactly are you experiencing?

Hi Stoltverd,

The player falls down only if his y-velocity is not 0. To see what’s going on at runtime, please log the velocity into your console while the player is running.

Furthermore, check the tilemap collider. There must not be any gaps. If there are gaps, the player might fall down even if that would not be possible in the real world. The game world in Unity is not the real world, so ‘impossible’ things might happen. Analyse the player’s environment. Maybe you’ll spot a potential problem.

1 Like

A slow fall. Very disimilar than what the course shows.

I didn’t think of logging the Y velocity. I’ll check it to see the acceleration while falling.
It almost feels like a feather falling.

image
It seems the character is falling at a regular speed. It just feels… slow? Maybe it’s just my perception?
EDIT: that’s “myRigidbody.velocity.y” baing logged btw

Fantastic. Now we know that the player has got y-velocity. This is important information because it could have been that something manipulates the player’s position directly. However, since the y-velocity obviously changes in your game, we can assume that either the gravity pulls the player down, or the code gives the additional player y-velocity, or both.

The slow fall in the beginning is generally correct. The gravity is an accelleration, so the object needs some time before it becomes faster. Similar to a car.

If the game object is extremely slow, that’s usually because of scale values different from (1, 1, 1). The values in the Rigidbody2D component could also be responsible. If the drag value is very high, the air friction is very high and slows the player down.

Another reason might be that the player is inside a bigger collider. Please check the Inspector of the background tilemap game object. It must not have any collider attached.

Privacy & Terms