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);
            }
        }
    }
  • 相关阅读:
    U盘启动盘恢复为普通盘
    TP框架模板中ifelse
    TP框架中多条件筛选
    日期选择器:jquery datepicker的使用
    配置本地环境,让内网可访问
    FlexSlider插件的详细设置参数
    CentOS+Nginx+PHP+MySQL详细配置(图解)
    Linux 服务器环境启动
    javascript自定义浏览器右键菜单
    强大实用的jQuery幻灯片插件Owl Carousel
  • 原文地址:https://www.cnblogs.com/mclll520/p/8028154.html
Copyright © 2011-2022 走看看