找回密码
 立即注册
查看: 4091|回复: 94

[源码] 第三人称character controller源码

[复制链接]
发表于 2012-11-25 14:19 | 显示全部楼层 |阅读模式
资源信息 Asset Information
资源名称: 第三人称character controller源码 (发帖教程)
版本: (版本)
资源等级: 1
资源格式: .zip (链接失效请点击帖子右下方举报通知管理员)
资源大小: 4MB (默认:MB)
下载地址: 站内下载 (购买积分)
点击查看原图
美丽分割线
本帖最后由 小米 于 2012-11-25 14:27 编辑

[code=javascript]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));
}[/code]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
发表于 2013-1-9 22:22 | 显示全部楼层
有源文件瓦
发表于 2013-1-9 22:23 | 显示全部楼层
有源文件瓦
发表于 2013-1-10 13:19 | 显示全部楼层
看起来真不错,下个看看
发表于 2013-1-12 01:11 | 显示全部楼层
这个帖子不错,大家快来顶起来!
发表于 2013-3-5 16:31 | 显示全部楼层
{:5_401:}{:5_401:}{:5_401:}
发表于 2013-3-15 11:33 | 显示全部楼层
角色控制入门经典,不错。
发表于 2013-5-3 11:56 | 显示全部楼层
{:5_397:}里面什么都没有啊?
发表于 2013-5-3 13:14 | 显示全部楼层
先从学习控制3D人物行走、动作开始,路漫漫,多谢楼主分享
发表于 2013-5-18 21:19 | 显示全部楼层
真是好东西!适合新手学习!
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-5-3 20:26 , Processed in 0.105607 second(s), 32 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表