Как ускорить остановку объекта (после ускорения с помощью Rigidbody) в Unity 3d?

В общем, я сделал персонажа у которого реализовал передвижение через AddRelativeforce и инпут систему. Но мне не нравиться, что мой перс как на коньках. я попробовал ускорить это с помощью умножения на десятичное число rigidbody.velocity. Он конечно стал замедляться, но только делает это очень резко и не сразу. Так вот, можно ли после применения силы, ускорить остановку нормально? Я думаю, что можно, просто я обезьяна. Обозначил точки интереса комментариями. Вот весь скрипт передвижения:

using UnityEngine;

[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(CapsuleCollider))]

public class PlayerMovement : MonoBehaviour
{
    [SerializeField] private float _speedPlayer = 0.3f;
    [SerializeField] private float _jumpForce = 1f;
    [SerializeField] private LayerMask _groundLayer;
    [SerializeField] private Transform _transformPlayer;
    [SerializeField] private float _maxVelocity;
    [SerializeField] private float _resistanceSpeed;
    private Rigidbody _rbPlayer;
    private CapsuleCollider _colliderPlayer;
    

    [SerializeField] public float SensitivityMouse;
    [SerializeField] public float RotationY;
    [SerializeField] public float RotationX;


    private bool _isGrounded
    {
        get
        {
            Vector3 bottomCenterPoint = new Vector3(_colliderPlayer.bounds.center.x, _colliderPlayer.bounds.min.y, _colliderPlayer.bounds.center.z);
            return Physics.CheckCapsule(_colliderPlayer.bounds.center, bottomCenterPoint, _colliderPlayer.bounds.size.x / 2 * 0.9f, _groundLayer);
        }
    }
       //точка интереса
    private Vector3 _movementVector
    {
        get
        {
            var horizontal = Input.GetAxis("Horizontal");
            var vertical = Input.GetAxis("Vertical");

            return new Vector3(horizontal, 0.0f, vertical);
        }
    }
        //end
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        _rbPlayer = GetComponent<Rigidbody>();
        _colliderPlayer = GetComponent<CapsuleCollider>();
        _rbPlayer.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;

        if (_groundLayer == gameObject.layer)
        {
            Debug.LogError("Player SortingLayer must be different from Ground SourtingLayer! А короче, ты обосрался со слоем игрока!!!");
        }
    }

    void Update()
    {
        //Верчу головой мышкой
        float MouseX = Input.GetAxis("MouseX") * SensitivityMouse * Time.deltaTime;
        float MouseY = Input.GetAxis("MouseY") * SensitivityMouse * Time.deltaTime;
        //Всё ещё верчу
        RotationY += MouseX;
        RotationX -= MouseY;
        RotationX = Mathf.Clamp(RotationX, -90f, 90f);
        transform.localRotation = Quaternion.Euler(0f, RotationY, 0f);
        _transformPlayer.localRotation = Quaternion.Euler(RotationX, 0f, 0f);       
    }
       //точка интереса
    void FixedUpdate()
    {
        JumpLogic();
        MoveLogic();
    }

    private void MoveLogic()
    {
        _rbPlayer.AddRelativeForce(_movementVector * _speedPlayer, ForceMode.Impulse);
        if (_rbPlayer.velocity.magnitude > _maxVelocity)
        {
            _rbPlayer.velocity = _rbPlayer.velocity.normalized * _maxVelocity;
        }
        if (_movementVector == Vector3.zero)
        {
            _rbPlayer.velocity *= _resistanceSpeed;
        }
    }
       //end
    private void JumpLogic()
    {
        if (_isGrounded && (Input.GetAxis("Jump") > 0))
        {
            _rbPlayer.AddForce(Vector3.up * _jumpForce, ForceMode.Impulse);
        }
    }
}

Напишите, если не хватает какой либо информации.


Ответы (0 шт):