Physics 全局物理性质和辅助方法。
public static float bounceThreshold { get; set; }
摘要:Two colliding objects with a relative velocity below this will not bounce (default 2). Must be positive.
两个相对速度低于此值的碰撞对象不会反弹(默认为2)。必须为正。
public static float sleepThreshold { get; set; }
摘要:The mass-normalized energy threshold, below which objects start going to sleep.
质量归一化的能量阈值,低于这个阈值,物体就会进入睡眠状态。
public static Vector3 gravity { get; set; }
摘要:The gravity applied to all rigid bodies in the scene. 作用于场景中的所有刚体的重力。
public static bool autoSimulation { get; set; }
摘要:Sets whether the physics should be simulated automatically or not.设置物理是否应该自动模拟。
OverlapSphere
获取球形范围内的碰撞器。
Raycast
检测射线是否碰到物体,并获取此物体。
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
bool b0 = Physics.Raycast(ray, out hit);
bool b1 = Physics.Raycast(ray, out hit, 500f);
bool b2 = Physics.Raycast(ray, out hit, 500f, 1 << 8);
bool b3 = Physics.Raycast(ray, out hit, 500f, 1 <<LayerMask.NameToLayer("Ground"));
bool b4 = Physics.Raycast(ray, out hit, 500f, ~(1 << 8));
Ray ray = new Ray(transform.position, transform.position + Vector3.forward*10);
bool b = Physics.Raycast(ray,Vector3.Distance(transform.position,transform.position+Vector3.forward*8));
RaycastAll
获取射线碰到的所有物体。