冻结后不会发生碰撞

时间:2018-12-18 06:39:33

标签: unity3d

我将建立砖制刹车游戏。在这里,当我冻结了护垫的y和x轴上的旋转时,则球和护垫的碰撞不起作用。球正穿过垫子?为什么会这样?我为这两个对象添加了rigid2D和碰撞器。这是我的剧本。

 using System.Collections; 
     using System.Collections.Generic;
      usingUnityEngine; 
      public class PaddleScript : MonoBehaviour {


     public Rigidbody2D rb;  
      public float speed;
      public float maxX;

    `

    // Use this for initialization

    void Start () {

        }
        // Update is called once per frame
            void Update () {
            float x = Input.GetAxis("Horizontal");
            if (x==0){
                Stop();
            }
            if (x<0){
                MoveLeft();
            }
            if (x>0){
                MoveRight();
            }
            Vector3 pos=transform.position;
            pos.x = Mathf.Clamp(pos.x,-maxX,maxX); //limit the boundary
            transform.position=pos;
     }

     `void MoveLeft(){ rb.velocity= new Vector2 (-speed,0); }` 


         void MoveRight() { rb.velocity= new Vector2 (speed,0); } 



         void Stop(){ rb.velocity= Vector 2.zero; } }

    `

0 个答案:

没有答案