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);
            }
        }
    }
  • 相关阅读:
    Centos8 静态IP设置
    2022年1月6号 LocalDateTime触发列无效问题
    2021年12月14日复盘(Oracle Not In,Limit 1000)
    2022年1月2日复盘 线上CPU飙升
    2021年12月16日复盘 JSQLParser 命中Oracle关键词报错
    2022年1月5号 on update CURRENT_TIMESTAMP无效情况记录
    2021年12月21日复盘 雪花算法 服务器时钟偏移错误
    Centos替换源
    2021年12月9日复盘 前端日期少8小时
    WPF中DataContext作用
  • 原文地址:https://www.cnblogs.com/mclll520/p/8028154.html
Copyright © 2011-2022 走看看