找回密碼
 注冊帳號

掃一掃,訪問微社區

collision.contacts 接觸點列表

2015-1-4 19:07| 發布者: 楊炎| 查看: 2150| 評論: 0|原作者: 蠻牛|來自: unity3d腳本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);

}

文章點評
女校游泳队彩金