unity3d 学习笔记_____Native2d 刚体、冲击、联合使用

| Mass | Mass of the rigidbody. |
| Linear Drag | Drag coefficient affecting positional movement. |
| Angular Drag | Drag coefficient affecting rotational movement. |
| Gravity Scale | Degree to which the object is affected by gravity. |
| Fixed Angle | Can the rigidbody rotate when forces are applied? |
| Is Kinematic | Is the rigidbody moved by forces and collisions? |
| Interpolate | How the object's movement is interpolated between physics updates (useful when motion tends to be jerky). |
| None | No movement smoothing is applied. |
| Interpolate | Movement is smoothed based on the object's positions in previous frames. |
| Extrapolate | Movement is smoothed based on an estimate of its position in the next frame. |
| Sleeping Mode | How the object "sleeps" to save processor time when it is at rest. |
| Never Sleep | Sleeping is disabled. |
| Start Awake | Object is initially awake. |
| Start Asleep | Object is initially asleep but can be woken by collisions. |
| Collision Detection | How collisions with other objects are detected. |
| Discrete | A collision is registered only if the object's collider is in contact with another during a physics update. |
| Continuous | A collision is registered if the object's collider appears to have contacted another between updates. |
碰撞器Collider 分为两种:
(1)刚体碰撞
(2) 触发碰撞、会穿透其它刚体
相应Collider组件中的is Trigger,两种都会产生碰撞事件
void OnCollisionEnter2D(Collision2D cod)
{
print (cod.gameObject.name);
if(cod.rigidbody)
cod.rigidbody.AddForce(new Vector2(0,500f));
}
void OnTriggerEnter2D(Collider2D other)
{
Destroy(other.gameObject);
}
两个方法都属于MonoBehaviour的Message 回调方法,注意区分它们的參数类型是不同的
另外还有 OnTriggerExit2D、OnTriggerStay2D、 OnCollisionExit2D、OnCollisionStay2D
关节的使用:
SpringJoint和DistantanceJoint有点类似多了弹性參数和频率设置(在unity中临时没看出效果)
hingeJoint 能够理解为一个环绕Z轴旋转的关节,能够设置响应moto、以及角度的限制
sliderJoint 滑动关节类似hingeJoint 以一个角度值设置Moto进行滑动,能够对距离(translation)进行限制
以下是一个用HingeJoint做的一个demo:
两仅仅小鸟同一时候加入HingeJoint 连接到盒子。后面的小鸟加下下面脚本控制方向键盘就可以前后运动
using UnityEngine;
using System.Collections; [RequireComponent(typeof(HingeJoint2D))]
public class MotoControl : MonoBehaviour { public float MotoSpeed = 0;
private JointMotor2D motor;
HingeJoint2D hj; // Use this for initialization
void Start () {
hj = GetComponent<HingeJoint2D>();
motor = hj.motor;
hj.useMotor = true;
motor = hj.motor;
motor.motorSpeed = MotoSpeed;
motor.maxMotorTorque = 10000;
} // Update is called once per frame
void Update () {
motor.motorSpeed = Input.GetAxis("Horizontal") * MotoSpeed;
hj.motor = motor;
}
}
做Demo时遇到的问题:
(1)刚開始用hj.motor.motorSpeed一直报错,后来分两步写最终没问题
motor = hj.motor;
motor.motorSpeed = MotoSpeed;
(2)错是没了,但是小车还是不走,最后知道还须要把motor对象又一次赋给HingeJoint
motor.motorSpeed = Input.GetAxis("Horizontal") * MotoSpeed;
hj.motor = motor;
其它一些经常使用的属性:
breakForce、breakTorque分别设定多大力、多大扭矩能给丫的拆了
connectedBody 连接的另外一个刚体的引用 (Joint2D中不存在)
hj.connectedBody = null;连接到一个空对象上
要想断开关节直接去掉关节组件 destroy(hj);
断开将发送 OnJointBreak Message.
版权声明:本文博客原创文章。博客,未经同意,不得转载。
unity3d 学习笔记_____Native2d 刚体、冲击、联合使用的更多相关文章
- Unity3D学习笔记——Rigdbody刚体组件
Rigdbody刚体组件:必须和碰撞体(Colliders)一起使用,否则会发生穿过的现象.碰撞体(Colliders)不是必须和刚体一起使用. 刚体的作用:使游戏物体能获得重力,接受外界的受力和扭力 ...
- unity3d学习笔记(一) 第一人称视角实现和倒计时实现
unity3d学习笔记(一) 第一人称视角实现和倒计时实现 1. 第一人称视角 (1)让mainCamera和player(视角对象)同步在一起 因为我们的player是生成的,所以不能把mainCa ...
- Unity3D学习笔记2——绘制一个带纹理的面
目录 1. 概述 2. 详论 2.1. 网格(Mesh) 2.1.1. 顶点 2.1.2. 顶点索引 2.2. 材质(Material) 2.2.1. 创建材质 2.2.2. 使用材质 2.3. 光照 ...
- Unity3D学习笔记3——Unity Shader的初步使用
目录 1. 概述 2. 详论 2.1. 创建材质 2.2. 着色器 2.2.1. 名称 2.2.2. 属性 2.2.3. SubShader 2.2.3.1. 标签(Tags) 2.2.3.2. 渲染 ...
- Unity3D学习笔记4——创建Mesh高级接口
目录 1. 概述 2. 详论 3. 其他 4. 参考 1. 概述 在文章Unity3D学习笔记2--绘制一个带纹理的面中使用代码的方式创建了一个Mesh,不过这套接口在Unity中被称为简单接口.与其 ...
- Unity3D学习笔记6——GPU实例化(1)
目录 1. 概述 2. 详论 3. 参考 1. 概述 在之前的文章中说到,一种材质对应一次绘制调用的指令.即使是这种情况,两个三维物体使用同一种材质,但它们使用的材质参数不一样,那么最终仍然会造成两次 ...
- Unity3D学习笔记7——GPU实例化(2)
目录 1. 概述 2. 详论 2.1. 实现 2.2. 解析 3. 参考 1. 概述 在上一篇文章<Unity3D学习笔记6--GPU实例化(1)>详细介绍了Unity3d中GPU实例化的 ...
- Unity3D学习笔记8——GPU实例化(3)
目录 1. 概述 2. 详论 2.1. 自动实例化 2.2. MaterialPropertyBlock 3. 参考 1. 概述 在前两篇文章<Unity3D学习笔记6--GPU实例化(1)&g ...
- Unity3D学习笔记12——渲染纹理
目录 1. 概述 2. 详论 3. 问题 1. 概述 在文章<Unity3D学习笔记11--后处理>中论述了后处理是帧缓存(Framebuffer)技术实现之一:而另外一个帧缓存技术实现就 ...
随机推荐
- 修改easyui datebox默认日期格式
问题描述: 根据jquery easyui datebox demo中给的示例,导入和使用datebox, 发现日期格式为: 6/22/2011, 其他的今天和关闭也是 Today, Close, 对 ...
- 【6】和作为连续序列s
称号:输入一个整数s,并打印出所有s整数的连续序列(含有至少2的数量). 如输入9,输出2.3.4和4.5两个序列 方案一:因为序列至少要2个数,则两个数上限值为(1+s)/2,我们能够枚举该序列的起 ...
- newinstance()和new有什么区别?(转)
在初始化一个类,生成一个实例的时候:newInstance() 和 new 有什么区别? 用newInstance与用new是区别的,区别在于创建对象的方式不一样,前者是使用类加载机制,那么为什么会有 ...
- 开源备份软件bacula安装记录--包括备份-恢复演练
该公司原先使用的备用机oracle-linux 5.7 不是很稳定执行.经常死机,新安装centos6.5, 即用bacula要备份的数据.在这里,有关安装故障记录,MEMO. 操作系统:centos ...
- URAL 1553. Caves and Tunnels 树链拆分
一颗树 每次出发点右键值是0 2操作模式1.第一i右键点值添加x 2.乞讨u至v在这条路上右上方值 树为主的连锁分裂称号 #include <cstdio> #include <cs ...
- App设计相关网站
http://sketch.im/ 设计素材 principle 动效软件 http://principleformac.com/ 官网 http://principlecn.com/ 中文网
- pdf转换为word小工具,挺好
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZGFwZW5nMDExMg==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- FastReport的再次使用
FastReport.Net是一款功能齐全的报表分析解决方案. 前两年工作的时候就是使用FastReport进行报表设计,只是当时使用的时候都是调用别人写好的帮助类,直接调用即可.当时让人觉得不明觉厉 ...
- Android开发学习总结(六)—— APK反编译(转)
学习和开发Android应用有一段时间了,今天写一篇博客总结一下Android的apk文件反编译.我们知道,Android应用开发完成之后,我们最终都会将应用打包成一个apk文件,然后让用户通过手机或 ...
- [HA]负载均衡:HAPROXY与KEEPALIVED强强联合
第一步:更改系统控制配置文件,同意分配虚拟IP(VIP) /etc/sysctl.conf net.ipv4.ip_nonlocal_bind=1 <pre style="word-w ...