第三人称character controller源码
本帖最后由 小米 于 2012-11-25 14:27 编辑private var walkSpeed : float = 1.0;
private var gravity= 100.0;
private var moveDirection : Vector3 = Vector3.zero;
private var charController : CharacterController;
function Start()
{
charController = GetComponent(CharacterController);
animation.wrapMode = WrapMode.Loop;
}
function Update ()
{
if(charController.isGrounded == true)
{
if(Input.GetAxis("Vertical") > .1)
{
if(Input.GetButton("Run"))
{
animation.CrossFade("run");
walkSpeed = 4;
}
else
{
animation["walk"].speed = 1;
animation.CrossFade("walk");
walkSpeed = 1;
}
}
else if(Input.GetAxis("Vertical") < -.1)
{
animation["walk"].speed = -1;
animation.CrossFade("walk");
walkSpeed = 1;
}
else
{
animation.CrossFade("idle");
}
// Create an animation cycle for when the character is turning on the spot
if(Input.GetAxis("Horizontal") && !Input.GetAxis("Vertical"))
{
animation.CrossFade("walk");
}
transform.eulerAngles.y += Input.GetAxis("Horizontal");
// Calculate the movement direction (forward motion)
moveDirection = Vector3(0,0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
}
moveDirection.y -= gravity * Time.deltaTime;
charController.Move(moveDirection * (Time.deltaTime * walkSpeed));
}
有源文件瓦 有源文件瓦 看起来真不错,下个看看 这个帖子不错,大家快来顶起来! {:5_401:}{:5_401:}{:5_401:} 角色控制入门经典,不错。 {:5_397:}里面什么都没有啊? 先从学习控制3D人物行走、动作开始,路漫漫,多谢楼主分享 真是好东西!适合新手学习!