Player falling with speed

Hello i have problem, player moves automatically with constant speed but when he fall, he fall with same speed, how do i stop speed movement in air and when he hit ground he will continue to move with speed before. Ty. Here is the code …

using UnityEngine;
using System.Collections;

public class playerBehavior : MonoBehaviour
{

    public float speedUnity;
    float speed;

    bool facingRight;
    bool facingLeft;

    Animator anim;
    Rigidbody2D rb;

    void Start ()
    {

        anim = GetComponent<Animator> ();
        rb = GetComponent<Rigidbody2D> ();

        facingRight = true;
        facingLeft = false;


   
    }
   
    // Update is called once per frame
    void Update ()
    {
        MovePlayer (speed);
        
        if(facingRight)
        {
            speed = speedUnity;
        }
        if(!facingRight)
        {
            speed = -speedUnity;
        }
    }

    void MovePlayer(float sendedSpeed)
    {
            if(sendedSpeed > 0)
        {
                rb.velocity = new Vector3(speed, rb.velocity.y, 0);
        }else
        {
                rb.velocity = new Vector3(speed, rb.velocity.y, 0);
            }
        }

You’ll need a means to check whether the player is on the ground or falling or some such combination? :slight_smile:

y but i dont know how to do it, if player dont touch platform (he is in air) to drop speed at 0 or 0.1 and ill play animation of falling

I made that post very recently to another user. If you read through it, let me know if it helps and you can make any progress based off of that. If you’re still stuck or need a bit more, please post an update. :slight_smile: