找回密碼
 注冊帳號

掃一掃,訪問微社區

charactercontroller.simplemove 簡單移動

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

摘要: charactercontroller.simplemove 簡單移動functionsimplemove(speed:vector3) : booldescription描述moves the character with speed.以一定的速度移動角色。velocity along the y-axis is ignored. speed is in met ...

charactercontroller.simplemove 簡單移動

functionsimplemove(speed:vector3) : bool

description描述

moves the character with speed.

以一定的速度移動角色

velocity along the y-axis is ignored. speed is in meters/s. gravity is automatically applied. returns if the character is grounded. it is recommended that you make only one call to move or simplemove per frame.

y 軸上速度被忽略。速度以米/秒為單位。重力被自動應用。返回如果角色著地。建議你每幀只調用一次move或者simplemove。

c#

javascript

using unityengine;

using system.collections;

public class example :monobehaviour{

public float speed = 3.0f;

public float rotatespeed = 3.0f;

void update() {

charactercontroller controller = getcomponent();

transform.rotate(0, input.getaxis("horizontal") * rotatespeed, 0);

vector3 forward = transform.transformdirection(vector3.forward);

float curspeed = speed * input.getaxis("vertical");

controller.simplemove(forward * curspeed);

}

}

var speed : float = 3.0;

var rotatespeed : float = 3.0;

function update () {

var controller : charactercontroller = getcomponent(charactercontroller);

// rotate around y - axis

//圍繞y軸旋轉

transform.rotate(0, input.getaxis ("horizontal") * rotatespeed, 0);

// move forward / backward

//向前后移動

var forward :vector3= transform.transformdirection(vector3.forward);

var curspeed : float = speed * input.getaxis ("vertical");

controller.simplemove(forward * curspeed);

}

@script requirecomponent(charactercontroller)

文章點評
女校游泳队彩金