- 最后登录
- 2017-5-15
- 注册时间
- 2012-3-1
- 阅读权限
- 90
- 积分
- 32973
- 纳金币
- 32806
- 精华
- 12
|
以下代码未经测试,仅做研究,特别是后一段代码。
操作说明:
Q 向上移动
E 向下移动
按住左Shift 加速
W A S D 和默认的相同
在unity3d中替换Fpswalker文件即可
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;
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)
下面另一个是我一牛B死党写的,更TMD的简练,半天我才搞懂。。
var sensitivity : float = .1;
var moveSpeed : float = 5;
function Update() {
transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * Time.deltaTime * sensitivity);
transform.Translate(Vector3.forward * Input.GetAxis("Vertical")* Time.deltaTime*moveSpeed ); //
transform.Translate(Vector3.right * Input.GetAxis("Horizontal") * Time.deltaTime* moveSpeed); //
transform.Translate(Vector3.up * Input.GetAxis("UpDown") * Time.deltaTime* moveSpeed);
}
别忘了还要到editproject settinginput 里面设置 UpDown |
|