Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 团结一致_C#_Unity3d - Fatal编程技术网

C# 团结一致

C# 团结一致,c#,unity3d,C#,Unity3d,当我松开箭头按钮时,我希望播放器立即停止移动,但由于rigidBody2D.addForce的作用,它会继续滑动一点。 这是我的密码: void Update () { forceX = 0f; var absVelX = Mathf.Abs (GetComponent<Rigidbody2D>().velocity.x); var absVelY = Mathf.Abs (GetComponent<Rigidbody2D>().velocity

当我松开箭头按钮时,我希望播放器立即停止移动,但由于rigidBody2D.addForce的作用,它会继续滑动一点。 这是我的密码:

void Update () {
    forceX = 0f;

    var absVelX = Mathf.Abs (GetComponent<Rigidbody2D>().velocity.x);
    var absVelY = Mathf.Abs (GetComponent<Rigidbody2D>().velocity.y);
    if (controller.moving.x != 0) {

        if (absVelX < maxVelocity.x) {
            forceX = speed * controller.moving.x;
            transform.localScale = new Vector3 (forceX > 0 ? 1 : -1, 1, 1);
            animator.SetInteger ("Controller", 1);

        }else if (controller.moving.x == 0) {
        }


    } else {
        animator.SetInteger ("Controller", 0);
    }

    GetComponent<Rigidbody2D>().AddForce(new Vector2 (forceX, 0));

}
void更新(){
力x=0f;
var absVelX=Mathf.Abs(GetComponent().velocity.x);
var absVelY=Mathf.Abs(GetComponent().velocity.y);
if(controller.moving.x!=0){
if(absVelX0?1:-1,1,1);
animator.SetInteger(“控制器”,1);
}else if(controller.moving.x==0){
}
}否则{
animator.SetInteger(“控制器”,0);
}
GetComponent().AddForce(新向量2(forceX,0));
}

提前谢谢。

当你给刚体加一个力时,物理引擎会增加它的速度。在每次物理更新中,物理引擎都会根据碰撞、摩擦等修改此速度,然后根据新速度计算新位置。如果希望刚体立即停止移动,则必须将速度设置为零:

GetComponent<Rigidbody2d>().velocity = Vector2.zero;
GetComponent().velocity=Vector2.0;

非常感谢,下次我需要专注于逻辑。