灵之舞 发表于 2013-1-7 19:47

Unity走路飞行脚本

var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;

function FixedUpdate() {
my=moveDirection.y;
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);

if (grounded) {

moveDirection *= speed;

} else {
moveDirection *= speed+transform.position.y/5;
moveDirection.y=my;
}
if(Input.GetKey ("e")) {
transform.Translate(0, -1, 0);
}

if (Input.GetKey ("q") ) {
transform.Translate(0, 1, 0);
}
if(Input.GetKey("left shift")) {
speed=6*5;
} else {
speed=6;
}
moveDirection.y -= gravity * Time.deltaTime;
moveDirection.z -= gravity * Time.deltaTime;

var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
@script RequireComponent(CharacterController)
private var myWalker: FPSWalker=null;
var maxHeight: float=250;
function Start () {
myWalker = gameObject.GetComponent(FPSWalker);
}

@script RequireComponent(FPSWalker)

自力 发表于 2013-3-26 13:35

发贴前不测试吗?单纯这个脚本怎么可能行呢?麻烦LZ测试下

softfeel 发表于 2017-7-9 11:09

很不错

苹果2013 发表于 2017-7-9 11:15

楼主是超人

softfeel 发表于 2017-7-9 10:49

好帖就是要顶

Answer 发表于 2017-7-9 11:17

很好哦

g3x7g 发表于 2017-7-9 11:07

不错不错

四两生煎包 发表于 2017-7-17 17:28

楼主是超人

impulseX 发表于 2017-7-17 16:54

真心顶

扫地工fsyhjhjh 发表于 2017-7-17 17:18

难得一见的好帖
页: [1]
查看完整版本: Unity走路飞行脚本