找回密碼
 注冊帳號

掃一掃,訪問微社區

charactercontroller.move 移動

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

摘要: charactercontroller.move 移動functionmove(motion:collisionflagsdescription描述a more complex move function taking absolute movement deltas.一個更加復雜的運動函數,每次都絕對運動。attempts to move the ...

charactercontroller.move 移動

functionmove(motion:collisionflags

description描述

a more complex move function taking absolute movement deltas.

一個更加復雜的運動函數,每次都絕對運動。

attempts to move the controller by motion, the motion will only be constrained by collisions. it will slide along colliders. collisionflags is the summary of collisions that occurred during the move. this function does not apply any gravity.

嘗試著通過動力移動控制器,動力只受限制于碰撞。它將沿著碰撞器滑動。collisionflags 是發生于move的碰撞的概要。這個函數不應用任何重力。

c#

javascript

using unityengine;

using system.collections;

public class example :monobehaviour{

public float speed = 6.0f;

public float jumpspeed = 8.0f;

public float gravity = 20.0f;

privatevector3.zero;

void update() {

charactercontroller controller = getcomponent();

if (controller.isgrounded) {

movedirection = newvector3(input.getaxis("horizontal"), 0, input.getaxis("vertical"));

movedirection = transform.transformdirection(movedirection);

movedirection *= speed;

if (input.getbutton("jump"))

movedirection.y = jumpspeed;

}

movedirection.y -= gravity * time.deltatime;

controller.move(movedirection * time.deltatime);

}

}

// this script moves the character controller forward

// and sideways based on the arrow keys.

//這個腳本用箭頭鍵向前移動和側移角色控制器。

// it also jumps when pressing space.

//當按下空格鍵時,它跳起。

// make sure to attach a character controller to the same game object.

//確保把一個character controller組件附加到同一個游戲物體上。

//it is recommended that you make only one call to move or simplemove per frame.

//建議你每幀只調用一次move或者simplemove。

var speed : float = 6.0;

var jumpspeed : float = 8.0;

var gravity : float = 20.0;

private var movedirection :vector3.zero;

function update() {

var controller : charactercontroller = getcomponent(charactercontroller);

if (controller.isgrounded) {

// we are grounded, so recalculate

// move direction directly from axes

//我們著地了,所以直接通過軸重新計算move direction。

movedirection =vector3(input.getaxis("horizontal"), 0,input.getaxis("vertical"));

movedirection = transform.transformdirection(movedirection);

movedirection *= speed;

if (input.getbutton ("jump")) {

movedirection.y = jumpspeed;

}

}

// apply gravity

//應用重力。

movedirection.y -= gravity * time.deltatime;

// move the controller

//移動控制器。

controller.move(movedirection * time.deltatime);

}

相關閱讀

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