简体   繁体   English

统一3D机芯滑动

[英]Unity 3D movement sliding

I am trying to make a FPS game but when I press w for a bit and then release it slides a bit further than wanted.我正在尝试制作 FPS 游戏,但是当我按下 w 一会儿然后松开它时,它会比想要的滑得更远。 I am pretty new to Unity and think it has something to do with the updates.我对 Unity 很陌生,并认为它与更新有关。 Code:代码:

public float moveSpeed = 5f;
public float jumpForce = 5f;
public CharacterController controller;

private Vector3  moveDirection;
public float gravityScale;

void Start()
{
    controller = GetComponent<CharacterController>();
}

void Update()
{
    float yStore = moveDirection.y;

    moveDirection = (transform.forward * Input.GetAxis("Vertical")) + (transform.right * Input.GetAxis("Horizontal"));
    moveDirection = moveDirection.normalized * moveSpeed;
    moveDirection.y = yStore;

    if (controller.isGrounded)
    {
        moveDirection.y = 0f;

        if (Input.GetButtonDown("Jump"))
        {
            moveDirection.y = jumpForce;
        }
    }

    moveDirection.y = moveDirection.y + (Physics.gravity.y * gravityScale);
    controller.Move(moveDirection * Time.deltaTime);
}

add a physics material to your ground and set the dynamic friction to 1. Next, set the static friction from 0.5 to 1. And last but not least, set the bounciness to 0.将物理材料添加到地面并将动态摩擦力设置为 1。接下来,将 static 摩擦力从 0.5 设置为 1。最后但同样重要的是,将弹性设置为 0。

Play around with these values a bit until you find something that is satisfactory.稍微调整一下这些值,直到找到满意的值。 here is the link to the documentation:这是文档的链接:

https://docs.unity3d.com/Manual/class-PhysicMaterial.html https://docs.unity3d.com/Manual/class-PhysicMaterial.html

it basically explains what each property does.它基本上解释了每个属性的作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM