charactercontroller.velocity 速度

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

摘要: charactercontroller.velocity 速度varvelocity:vector3description描述the current relative velocity of the character (see notes).角色当前的相对速度(参见注解)。this allows you to track how fast the char ...

charactercontroller.velocity 速度

varvelocity:vector3

description描述

the current relative velocity of the character (see notes).

角色当前的相对速度(参见注解)。

this allows you to track how fast the character is actually walking for example when he is stuck at a wall this value will be the zero vector.

它允许你追踪角色究竟移动有多快,例如,当他被卡在墙壁里,这个值将变为0向量。

note: the velocity returned is simply the difference in distance for the current timestep before and after a call to charactercontroller.move or charactercontroller.simplemove. the velocity is relative because it won't track movements to the transform that happen outside of the charactercontroller (e.g. character parented under another moving transform, such as a moving vehicle).

注解:返回速度在调用charactercontroller.move或者charactercontroller.simplemove之前和之后的时刻是不同的。速度是相对的,因为它不会追踪发生在charactercontroller之外的变换的运动(例如,角色继承于另一个运动着的变换之下,比如一个运动着的车辆)。

c#

javascript

using unityengine;

using system.collections;

public class example :monobehaviour{

void update() {

charactercontroller controller = getcomponent();

vector3 horizontalvelocity = controller.velocity;

horizontalvelocity = newvector3(controller.velocity.x, 0, controller.velocity.z);

float horizontalspeed = horizontalvelocity.magnitude;

float verticalspeed = controller.velocity.y;

float overallspeed = controller.velocity.magnitude;

}

}

function update () {

var controller : charactercontroller = getcomponent(charactercontroller);

var horizontalvelocity :vector3= controller.velocity;

horizontalvelocity =vector3(controller.velocity.x, 0, controller.velocity.z);

// the speed on the x-z plane ignoring any speed

//忽略y轴的x-z平面上的速度。

var horizontalspeed : float = horizontalvelocity.magnitude;

// the speed from gravity or jumping

//重力或者跳跃引起的速度。

var verticalspeed : float = controller.velocity.y;

// the overall speed

//总体速度。

var overallspeed : float = controller.velocity.magnitude;

}

相关阅读

文章点评
相关文章