Unity 常用脚本:Physics

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

获取射线碰到的所有物体。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值