Physics.IgnoreCollision 忽略碰撞

static function IgnoreCollision (collider1 : Collider, collider2 : Collider, ignore : bool = true) : void

Description描述

Makes the collision detection system ignore all collisions between collider1 and collider2.

使碰撞体1和碰撞体2的碰撞侦测无效。

This is most useful for making eg. projectiles not collide with the object shooting them.

如果要忽略炮弹和发射物之间的碰撞侦测,这种情况下是很有用的。

IgnoreCollision has a few limitations: 1) It is not persistent. This means ignore collision state will not be stored in the editor when saving a scene. 2) You can only apply the ignore collision to colliders in active game objects. When deactivating the collider or attached rigidbody the IgnoreCollision state will be lost and you have to call Physics.IgnoreCollision again.

忽略碰撞情况下的限制:1. 保存场景时忽略状态不能保存。2.只能在活动的对象物体上应用。如果用在失效的物体上,必须要调用一次physics.IgnoreCollision.

参见: Physics.IgnoreLayerCollision

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public Transform bulletPrefab;
	void Start() {
		Transform bullet = Instantiate(bulletPrefab) as Transform;
		Physics.IgnoreCollision(bullet.collider, collider);
	}
}
// Instantiate a bullet and make it ignore collisions with this object.
// 实例化一个子弹,忽略与发射体的碰撞。

var bulletPrefab : Transform;
function Start () {
	var bullet = Instantiate(bulletPrefab) as Transform;
	Physics.IgnoreCollision(bullet.collider, collider);
}
最后修改:2011年4月9日 Saturday 12:39

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。