Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.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_Collision Detection - Fatal编程技术网

C# 为什么赢了';我的刚体在碰撞时不能停止移动吗?

C# 为什么赢了';我的刚体在碰撞时不能停止移动吗?,c#,unity3d,collision-detection,C#,Unity3d,Collision Detection,我不熟悉团结 下面是我的简单字符控制器C#脚本。我使用3d立方体和框碰撞器以及刚体作为我的墙和播放器。目前,当我的播放器接触到一堵墙时,它会继续运行 为什么我的脚本不起作用 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Controller : MonoBehaviour { public float speed = 180; priva

我不熟悉团结

下面是我的简单字符控制器C#脚本。我使用3d立方体和框碰撞器以及刚体作为我的墙和播放器。目前,当我的播放器接触到一堵墙时,它会继续运行

为什么我的脚本不起作用

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Controller : MonoBehaviour {

    public float speed = 180;

    private Rigidbody rig;

    private Vector3 movement;
    // Use this for initialization
    void Start () {

        rig = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void FixedUpdate () {

        if (rig.velocity.magnitude <= 0)
        {
            if (Input.GetKeyUp("up"))
                rig.velocity = new Vector3(0, 0, rig.position.z * speed );            
            else if (Input.GetKeyUp("down"))
                rig.velocity = new Vector3(0, 0, rig.position.z * speed * -1);
            else if (Input.GetKeyUp("right"))
                rig.velocity = new Vector3(rig.position.x * speed, 0, 0);
            else if (Input.GetKeyUp("left"))
                rig.velocity = new Vector3(rig.position.x * speed * -1, 0, 0);
        }
    }

    void OnCollisionEnter(Collision collision)
    {
            rig.velocity = Vector3.zero;
    }
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
公共类控制器:单行为{
公共浮动速度=180;
私人刚体钻机;
私人矢量运动;
//用于初始化
无效开始(){
rig=GetComponent();
}
//每帧调用一次更新
无效固定更新(){

如果(rig.velocity.magnitude上面的脚本起作用了…我的y位置高于墙壁的位置,所以从来没有发生任何碰撞。我觉得很笨。留下帖子提醒我失败。

上面的脚本起作用了…我的y位置高于墙壁的位置,所以从来没有发生任何碰撞。我觉得很笨。留下帖子提醒我失败。

上面的脚本起作用了…我的y位置高于墙壁的位置,所以从来没有发生任何碰撞。我觉得很笨。离开帖子了作为我失败的提醒