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)技术实现之一:而另外一个帧缓存技术实现就 ...
随机推荐
- chromium for android v34 2dcanvas硬件渲染实现分析
这篇接着上一篇2dcanvas硬件绘制,分析保存绘制结果的texture被合成到on screen framebuffer上的过程. 1.webkit为canvas元素相应的render树节点Rend ...
- mysql回想一下基础知识
创建数据库 creat table test( #整数通常用于int test_id int, #十进制通常使用decimal test_price decimal, #普通文本通常使用.并使用Def ...
- paip.java UrlRewrite 的原理and实现 htaccess正則表達式转换
paip.java UrlRewrite 的原理and实现 htaccess正則表達式转换 #---KEYWORD #-正則表達式 正則表達式 表示 非指定字符串开头的正则 排除指定文件夹.. 作者 ...
- mybaits使用存储过程
如何使用Mybaits调用数据库存储过程,按以下顺序Oracle案例库: 1.在数据库中创建以下存储过程: create or replace procedure pro_hello(p_result ...
- poj 3414 Pots (bfs+线索)
Pots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10071 Accepted: 4237 Special J ...
- 基于Spring + Spring MVC + Mybatis 高性能web构建
基于Spring + Spring MVC + Mybatis 高性能web构建 一直想写这篇文章,前段时间 痴迷于JavaScript.NodeJs.AngularJs,做了大量的研究,对前后端交互 ...
- RH033读书笔记(14)-Lab 15 Switching Users and Setting a Umask
Lab 15 Switching Users and Setting a Umask Goal: Become familiar with the use of several essential c ...
- 在Linux下,在网络没有配置好前,怎样查看网卡的MAC地址?
在Linux下,在网络没有配置好前,怎样查看网卡的MAC地址? 使用 dmesg 与 grep 命令来实际,例如以下: [root@localhost ~]# dmesg | grep eth e10 ...
- struts 1.x 原理
Struts 当我接触到这个框架的时候.我就在想为什么是struts,而不是什么CraigFramework.结构.支撑,这样来理解也不难怪了. 为什么须要struts? 在struts in act ...
- Jenkins(二) 安装、新建Jobs与删除及SVN配置(转)
官网首页(https://jenkins-ci.org/)就提供了windows版本的Jenkins安装包.可以自己下载一个用于学习.安装后自动打开http://localhost:8080,就可以看 ...