unity关节(joint)讲解
来源:互联网 发布:js 数组排序 按大小 编辑:程序博客网 时间:2024/04/29 16:48
关节
关节组件可以添加至多个游戏对象中,而添加关节的游戏对象将通过关节连接在一起并且感觉连带的物理效果。需要注意的是:关节必须依赖于刚体组件。
关节介绍
关节一共分为5大类:链条关节,固定关节,弹簧关节,角色关节和可配置关节。
链条关节(hinge joint):将两个物体以链条的形式绑在一起,当力量大于链条的固定力矩时,两个物体就会产生相互的拉力。
固定关节(fixed joint):将两个物体永远以相对的位置固定在一起,即使发生物理改变,它们之间的相对位置也将不变。
弹簧关节(spring joint):将两个物体以弹簧的形式绑定在一起,挤压它们会得到向外的力,拉伸它们将得到向里的力。
角色关节(character joint):可以模拟角色的骨骼关节。
可配置关节(configurable joint):可以模拟任意关节的效果。
关节是一个游戏组件,在导航菜单栏中选择component——physics然后从中选择一种关节组件,即可完成关节组件的添加。
使用breakforce可设置关节断裂的力,一旦力超过它,关节将会断裂。断裂时,通过onjointbreakforce方法可监听相关事件。
下面给个实例:
using UnityEngine;using System.Collections;public class Script_06_10 : MonoBehaviour { //链接关节游戏对象 GameObject connectedObj = null; //当前链接的关节组件 Component jointComponent = null; void Start() { //获得链接关节的游戏对象 connectedObj = GameObject.Find("Cube1"); } void OnGUI() { if(GUILayout.Button("添加链条关节")) { ResetJoint(); jointComponent = gameObject.AddComponent("HingeJoint"); HingeJoint hjoint = (HingeJoint)jointComponent; connectedObj.rigidbody.useGravity = true; hjoint.connectedBody = connectedObj.rigidbody; } if(GUILayout.Button("添加固定关节")) { ResetJoint(); jointComponent =gameObject.AddComponent("FixedJoint"); FixedJoint fjoint = (FixedJoint)jointComponent; connectedObj.rigidbody.useGravity = true; fjoint.connectedBody = connectedObj.rigidbody; } if(GUILayout.Button("添加弹簧关节")) { ResetJoint(); jointComponent =gameObject.AddComponent("SpringJoint"); SpringJoint sjoint = (SpringJoint)jointComponent; connectedObj.rigidbody.useGravity = true; sjoint.connectedBody = connectedObj.rigidbody; } if(GUILayout.Button("添加角色关节")) { ResetJoint(); jointComponent =gameObject.AddComponent("CharacterJoint"); CharacterJoint cjoint = (CharacterJoint)jointComponent; connectedObj.rigidbody.useGravity = true; cjoint.connectedBody = connectedObj.rigidbody; } if(GUILayout.Button("添加可配置关节")) { ResetJoint(); jointComponent =gameObject.AddComponent("ConfigurableJoint"); ConfigurableJoint cojoint = (ConfigurableJoint)jointComponent; connectedObj.rigidbody.useGravity = true; cojoint.connectedBody = connectedObj.rigidbody; } } //重置关节 void ResetJoint(){ //销毁之前添加的关节组件 Destroy (jointComponent); //重置对象位置 this.transform.position = new Vector3(821.0f,72.0f,660.0f); connectedObj.gameObject.transform.position = new Vector3(805.0f,48.0f,660.0f); //不敢应重力 connectedObj.rigidbody.useGravity = false; }}运行后:
点击左边按钮,两个正方体便会下落实现不同的关节效果。主要是上述的代码很值得参考与细读。
阅读全文
0 0
- unity关节(joint)讲解
- Joint关节
- 【静下心学习Unity】学习笔记 (三)Unity Physics - Hinge Joint(铰链关节) 实现门的功能
- Unity物理关节:关节简介(可配置关节)
- Hinge Joint 铰链关节
- Character Joint 角色关节
- Fixed Joint 固定关节
- Spring Joint弹簧关节
- Unity 关节
- unity 关节
- unity关节
- Configrable Joint 可配置关节
- Unity物理引擎:关节简介(铰链关节)
- Unity物理引擎:关节简介(固定关节)
- Unity物理引擎:关节简介(弹簧关节)
- Unity物理引擎:关节简介(角色关节)
- unity3d关节物体连接方式 Joint 简介
- 五类关节属性Joint的用法
- Tyvj1077
- python-6-enumerate
- C#中Dictionary的用法
- uva 10385 一个单峰函数(由min(很多一次函数)构成)和一个一次函数的差值 也是单峰函数
- Google FlatBuffers——开源、跨平台的新一代序列化工具
- unity关节(joint)讲解
- mac下配置phantomjs
- jQuery给对象绑定,解绑事件
- [git]Git使用流程(五)
- screencapture
- 那些年、一起追过的Spring--(4)----注解
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)
- 数据挖掘之关联分析一(基本概念)
- Maven War 插件Classes文件夹打为Jar包的Bug与解决方法