Как убрать скольжение в Unity 2D
В Unity я столкнулся с проблемой "скольжения" персонажа после того как он перемещается. Вроде говорили мне что надо сделать так: rb.velocity = new Vector2(0, rb.velocity.y);
. Вроде работает, но всё равно видно, что происходит то самое скольжение. Помогите если вы знаете как это сделать чтобы работало на 100%. Код передвижения смотрите ниже.
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class контроллер : MonoBehaviour
{
public float speed = 2f;
Rigidbody2D rb;
SpriteRenderer sr;
public float JumpForce = 50f;
void Start()
{
rb = GetComponent<Rigidbody2D>();
sr = GetComponent<SpriteRenderer>();
}
void Update()
{
if (Input.GetAxis("Horizontal") < 0)
{
sr.flipX = true;
}
else if (Input.GetAxis("Horizontal") > 0)
{
sr.flipX = false;
}
}
void FixedUpdate()
{
if (Input.GetAxis("Horizontal") > 0)
{
rb.velocity = new Vector2(speed, rb.velocity.y);
}
else if (Input.GetAxis("Horizontal") < 0)
{
rb.velocity = new Vector2(-speed, rb.velocity.y);
}
if (Input.GetKey(KeyCode.Space) && Mathf.Abs(rb.velocity.y) < 0.05)
{
rb.AddForce(new Vector2(0, JumpForce), ForceMode2D.Impulse);
}
}
}
Источник: Stack Overflow на русском