collision.contacts 接触点列表

2015-1-4 19:07| 发布者: 杨炎| 查看: 1848| 评论: 0|原作者: 蛮牛|来自: yzc88亚洲城脚本manual

摘要: collision.contacts 接触点列表varcontacts:contactpointdescription描述the contact points generated by the physics engine.接触点由物理引擎产生。every contact contains a contact point, normal and the two ...

collision.contacts 接触点列表

varcontacts:contactpoint[]

description描述

the contact points generated by the physics engine.

接触点由物理引擎产生。

every contact contains a contact point, normal and the two colliders that collided (seecontactpoint). from insideoncollisionstayoroncollisionenteryou can always be sure that contacts has at least one element.

每一个接触(contact)包含一个接触点、法线和两个碰撞的碰撞器(看contactpoint)。在oncollisionstay或oncollisionenter里你确保contacts至少有一个元素。

c#

javascript

using unityengine;

using system.collections;

public class example :monobehaviour{

void oncollisionstay(collision collision) {

foreach (contactpointcontact in collision.contacts) {

print(contact.thiscollider.name + " hit " + contact.othercollider.name);

debug.drawray(contact.point, contact.normal, color.white);

}

}

}

function oncollisionstay(collision : collision) {

// check if the collider we hit has a rigidbody

// then apply the force

//检查如果碰撞的碰撞器有刚体,然后应用力

for (var contact : contactpoint in collision.contacts) {

print(contact.thiscollider.name + " hit " + contact.othercollider.name);

// visualize the contact point

//可视化接触点

debug.drawray(contact.point, contact.normal, color.white);

}

}

c#

javascript

using unityengine;

using system.collections;

public class example :monobehaviour{

publictransformexplosionprefab;

void oncollisionenter(collision collision) {

contactpointcontact = collision.contacts[0];

quaternionrot =quaternion.fromtorotation(vector3.up, contact.normal);

vector3 pos = contact.point;

instantiate(explosionprefab, pos, rot);

destroy(gameobject);

}

}

// a grenade

//一个手榴弹

// - instantiates a explosion prefab when hitting a surface

// - then destroys itself

//当碰到表面时,实例化一个爆炸预设

var explosionprefab :transform;

function oncollisionenter(collision : collision) {

// rotate the object so that the y-axis faces along the normal of the surface

//旋转物体,y轴面沿着表面的法线。

var contact = collision.contacts[0];

var rot = quaternion.fromtorotation(vector3.up, contact.normal);

var pos = contact.point;

instantiate(explosionprefab, pos, rot);

// destroy the projectile

//销毁手榴弹

destroy (gameobject);

}

文章点评