zoukankan      html  css  js  c++  java
  • 物体在一定范围自有碰撞

    /*              #########                       
                  ############                     
                  #############                    
                 ##  ###########                   
                ###  ###### #####                  
                ### #######   ####                 
               ###  ########## ####                
              ####  ########### ####               
             ####   ###########  #####             
            #####   ### ########   #####           
           #####   ###   ########   ######         
          ######   ###  ###########   ######       
         ######   #### ##############  ######      
        #######  #####################  ######     
        #######  ######################  ######    
       #######  ###### #################  ######   
       #######  ###### ###### #########   ######   
       #######    ##  ######   ######     ######   
       #######        ######    #####     #####    
        ######        #####     #####     ####     
         #####        ####      #####     ###      
          #####       ###        ###      #        
            ###       ###        ###              
             ##       ###        ###               
    __________#_______####_______####______________
        身是菩提树,心如明镜台,时时勤拂拭,勿使惹尘埃。
                    我们的未来没有BUG              
    * ==============================================================================
    * Filename: AnimationFlashScript
    * Created:  $time$
    * Author:   WYC
    * Purpose:  自有匀速碰撞
    * ==============================================================================
    */
    using UnityEngine;
    
    public class RenCollier : MonoBehaviour {
        public float         speed;
        public    Rigidbody    rigidbody;
        RaycastHit hit;
    
        float stay;
    
        void Start () {
            transform.eulerAngles = new Vector3(0,0, Random.value*360);
        }
        
        void FixedUpdate () {
            transform.Translate (Vector3.right * speed * Time.deltaTime);
        }
    
        void OnCollisionEnter(){
            Vector3 fwd = transform.TransformDirection(Vector3.right);
            Ray ray = new Ray(transform.position,transform.right);
    
            if (Physics.Raycast(ray,out hit , 20f)){
                Vector3 rayDir = Vector3.Reflect(ray.direction,hit.normal);
                float rot = Mathf.Atan2(rayDir.y,rayDir.x) * Mathf.Rad2Deg;
                transform.localEulerAngles = new Vector3(0,0,rot);
            }
        }
    
        void OnCollisionStay(){
            stay++;
    
            if (stay > 10) {
                stay = 0;
                transform.eulerAngles = new Vector3(0,0, Random.value*360);
            }
        }
    }
  • 相关阅读:
    poj 3096 Surprising Strings (set)
    hdu 4038 stone
    STL set 使用总结
    poj 3185 The Water Bowls (bfs 加未压缩)
    QPixmap显示图片
    addStretch的作用 .
    Qt SizeHint()
    StyleSheet
    linux编程守护进程编写
    Qt样式表的使用
  • 原文地址:https://www.cnblogs.com/mclll520/p/8028154.html
Copyright © 2011-2022 走看看