版本:Unity 6 (6000.0)
语言英语
  • C#

CollisionDetectionMode.Continuous

建议更改

成功!

感谢您帮助我们提高 Unity 文档质量。即使我们无法接受所有提交,但我们确实会阅读来自用户提出的每项建议更改,并在适用的地方进行更新。

关闭

提交失败

由于某种原因,您建议的更改无法提交。请在几分钟后<a>重试</a>。感谢您花时间帮助我们提高 Unity 文档质量。

关闭

取消

说明

与静态网格几何碰撞的连续碰撞检测已开启。

即使碰撞发生在两次 FixedUpdate 步骤之间,系统也会检测到该 Rigidbody 路径上的任何静态网格几何碰撞。静态网格几何是指没有任何 Rigidbody 附加的 MeshCollider。这也可以阻止被设定为 ContinuousDynamic 模式的 Rigidbody 穿透该 Rigidbody。

//This script allows you to switch collision detection mode at the press of the space key
//Attach this script to a GameObject
//Click the GameObject, go to its Inspector and click the Add Component Button. Then, go to Physics>Rigidbody.

using UnityEngine; using UnityEngine.UI;

public class Example : MonoBehaviour { Rigidbody m_Rigidbody;

void Start() { m_Rigidbody = GetComponent<Rigidbody>(); }

public void Update() { //Press the space key to switch the collision detection mode if (Input.GetKeyDown(KeyCode.Space)) SwitchCollisionDetectionMode(); }

//Switch between the different Collision Detection Modes void SwitchCollisionDetectionMode() { switch (m_Rigidbody.collisionDetectionMode) { //If the current mode is continuous, switch it to continuous dynamic mode case CollisionDetectionMode.Continuous: m_Rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; break; //If the current mode is continuous dynamic, switch it to discrete mode case CollisionDetectionMode.ContinuousDynamic: m_Rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative; break;

// If the curren mode is continuous speculative, switch it to discrete mode case CollisionDetectionMode.ContinuousSpeculative: m_Rigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete; break;

//If the current mode is discrete, switch it to continuous mode case CollisionDetectionMode.Discrete: m_Rigidbody.collisionDetectionMode = CollisionDetectionMode.Continuous; break; } } }