I make simple Player Movment (2D) and i moving player fall (https://puu.sh/x7zFb/5f9e8f3c7f.mp4) how to fix it?
Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovment : MonoBehaviour {
// public float maxJumpSpeed = 3;
public float maxSpeed = 3;
public float speed = 50f;
public float jumpSpeed = 250f;
private Rigidbody2D rb2d;
public bool grounded;
public Transform groundCheckPoint;
public float groundCheckRadius;
public LayerMask groundLayer;
// Use this for initialization
void Start () {
rb2d = gameObject.GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
grounded = Physics2D.OverlapCircle(groundCheckPoint.position,groundCheckRadius, groundLayer);
if (Input.GetAxis("Horizontal") < -0.1f)
{
transform.localScale = new Vector3(-1, 1, 1);
}
if (Input.GetAxis("Horizontal") > 0.1f)
{
transform.localScale = new Vector3(1, 1, 1);
}
}
void FixedUpdate () {
float h = Input.GetAxis ("Horizontal");
//float w = Input.GetAxis("Vertical");
rb2d.AddForce(Vector2.right * speed * h);
Vector3 easeVelocity = rb2d.velocity;
easeVelocity.y = rb2d.velocity.y;
easeVelocity.z = 0.0f;
easeVelocity.x = 0.75f;
if (grounded)
{
easeVelocity = rb2d.velocity;
}
if (rb2d.velocity.x > maxSpeed)
{
rb2d.velocity = new Vector2(maxSpeed, rb2d.velocity.y);
}
if (rb2d.velocity.x < -maxSpeed)
{
rb2d.velocity = new Vector2(-maxSpeed, rb2d.velocity.y);
}
if (Input.GetKeyDown(KeyCode.Z) && grounded)
{
rb2d.AddForce(Vector2.up * jumpSpeed);
}
}
}
player setings:
and