charactercontroller.move 移动

2015-1-4 11:07| 发布者: 杨炎| 查看: 1568| 评论: 0|原作者: 蛮牛|来自: yzc88亚洲城脚本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);

}

相关阅读

文章点评
相关文章