|
|
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.