【Unity3d学习笔记】刚体碰撞和关节
来源:互联网 发布:美工设计的岗位职责 编辑:程序博客网 时间:2024/04/26 14:34
3.20
RigidbodyConstant Forceusing UnityEngine;using System.Collections;public class AddForce : MonoBehaviour {void FixedUpdate (){if(Input.GetKeyDown(KeyCode.UpArrow)){ //当输入向上的按键时GetComponent<Rigidbody>().AddForce(0,60,0); //给物体添加一个向上的力,这里用的是Unity5的写法,Unity4.x中一般用Rigidbody.AddForce()}}/*Rigidbody rb = GetComponent<Rigidbody> ();if(Input.GetKeyDown(KeyCode.UpArrow)){rb.AddForce(0,60,0); //添加力的另一种写法}*/
3.21
using UnityEngine; using System.Collections; public class AddForce : MonoBehaviour { public float x_power = 100.0f; public float y_power = 0.0f; public float z_power = 0.0f; //给x,y,z轴添加变量的力void FixedUpdate (){ if(Input.GetKeyDown(KeyCode.RightArrow)){ GetComponent().AddForce(x_power,y_power,z_power); } } void OnCollisionEnter(Collision other){ //当物理碰撞进入时 Debug.Log (other.gameObject); //输出被碰撞的物体的名字 } }
3.22
using UnityEngine;using System.Collections;public class CollisionTest : MonoBehaviour { void OnCollisionEnter(Collision other){ Debug.Log ("碰撞进入"); } void OnCollisionStay(Collision other){ Debug.Log ("碰撞持续"); } void OnCollisionExit(Collision other){ Debug.Log ("碰撞出去"); }} //输出物体的不同状态
using UnityEngine;using System.Collections;public class CollisionTest : MonoBehaviour { void OnCollisionEnter(Collision other){ //当物体碰撞进入时 if (other.gameObject.name == "Cube") { //若被碰撞的物体是立方体 Destroy(other.gameObject); //则立方体消失 } }}
创建physic material,改变Bounciness,可以改变弹跳能力。
3.23
using UnityEngine;using System.Collections;public class TriggerTest : MonoBehaviour { void OnTriggerEnter(Collider other){//加在被碰撞的物体上 Debug.Log ("碰撞持续"); Rigidbody rb = other.GetComponent<Rigidbody>(); rb.AddForce(Vector3.up * 20,ForceMode.Acceleration); //Acceleration指加速度 }}
using UnityEngine;using System.Collections;public class AddForce : MonoBehaviour { void OnMouseDown(){ GetComponent<Rigidbody> ().AddForce (-Vector3.forward * 500); }} //推拉门的一个效果,利用hinge joint
0 0
- 【Unity3d学习笔记】刚体碰撞和关节
- unity3d 学习笔记_____Native2d 刚体、碰撞器、关节的使用
- Unity3d 刚体碰撞器
- unity3d刚体和碰撞检测学习一:新建一个plane和一个sphere,却碰撞检测失败的问题
- unity3D学习之物体添加刚体及碰撞。
- unity3d之刚体碰撞器和触发器的一些知识
- 自学Unity3D游戏开发(3)刚体和碰撞
- 碰撞体和刚体
- Unity3D学习笔记 碰撞检测
- 【Unity3D学习笔记】碰撞体
- Unity3D学习之刚体
- unity3d 理解刚体(Rigidbody)和碰撞体(Collider)以及触发器(Is Trigger),边学边更新
- unity3d 理解刚体(Rigidbody)和碰撞体(Collider)以及触发器(Is Trigger)
- unity3d 理解刚体(Rigidbody)和碰撞体(Collider)以及触发器(Is Trigger),边学边更新
- unity3d 理解刚体(Rigidbody)和碰撞体(Collider)以及触发器(Is Trigger),边学边更新
- unity3d 理解刚体(Rigidbody)和碰撞体(Collider)以及触发器(Is Trigger),边学边更新
- unity3d 理解刚体(Rigidbody)和碰撞体(Collider)以及触发器(Is Trigger),边学边更新
- Unity3D学习笔记(十一)物理引擎:刚体与力
- UNIX网络编程之旅-配置unp.h头文件环境
- Android——View宽高的设置和多种获取宽高的方法、layout_grivaty与grivaty的区别
- JAVA反射会降低你的程序性能吗?
- ScrollView阻尼效果
- operator 与&operator
- 【Unity3d学习笔记】刚体碰撞和关节
- 基于python的新浪微博模拟登陆
- RSA加密算法原理
- Java开发中的23种设计模式详解
- 自制数据结构mindmap
- 自制操作系统原理mindmap
- Java基本语法笔记
- Android 网络通信框架Volley的解析
- android内存管理工具MAT的使用