找回密碼
 注冊帳號

掃一掃,訪問微社區

charactercontroller.oncontrollercolliderhit 控制碰撞器碰撞

2015-1-4 11:17| 發布者: 楊炎| 查看: 4780| 評論: 0|原作者: 蠻牛|來自: unity3d腳本manual

摘要: charactercontroller.oncontrollercolliderhit 控制碰撞器碰撞functiononcontrollercolliderhit(hit:controllercolliderhit) : voiddescription描述oncontrollercolliderhit is called when the controller hits a c ...

charactercontroller.oncontrollercolliderhit 控制碰撞器碰撞

functiononcontrollercolliderhit(hit:controllercolliderhit) : void

description描述

oncontrollercolliderhit is called when the controller hits a collider while performing a move.

角色控制器" target="_blank" class="relatedlink">角色控制器碰到一個可執行移動的碰撞器時,oncontrollercolliderhit被調用。

this can be used to push objects when they collide with the character

這個可以被用于推動物體,當它們碰撞角色時。

c#

javascript

using unityengine;

using system.collections;

public class example :monobehaviour{

public float pushpower = 2.0f;

void oncontrollercolliderhit(controllercolliderhit hit) {

rigidbody body = hit.collider.attachedrigidbody;

if (body == null || body.iskinematic)

return;

if (hit.movedirection.y < -0.3f)

return;

vector3 pushdir = newvector3(hit.movedirection.x, 0, hit.movedirection.z);

body.velocity = pushdir * pushpower;

}

}

// this script pushes all rigidbodies that the character touches

// 這個腳本推動所有的角色碰撞到的剛體。

var pushpower = 2.0;

function oncontrollercolliderhit (hit : controllercolliderhit) {

var body : rigidbody = hit.collider.attachedrigidbody;

// no rigidbody

// 沒有剛體。

if (body == null || body.iskinematic)

return;

// we dont want to push objects below us

// 我們不想推動在我們下邊的物體。

if (hit.movedirection.y < -0.3)

return;

// calculate push direction from move direction,

// we only push objects to the sides never up and down

// 通過移動方向計算推動方向,我們只把物體推到兩側,從不向上和向下推。

var pushdir :vector3(hit.movedirection.x, 0, hit.movedirection.z);

// if you know how fast your character is trying to move,

// then you can also multiply the push velocity by that.

// 如果你知道你的角色移動的有多快,那么你也可以用它乘以推動速度。

// apply the push

// 應用推力。

body.velocity = pushdir * pushpower;

}

相關閱讀

文章點評
相關文章
女校游泳队彩金