zoukankan      html  css  js  c++  java
  • 几种常见的移动方式

     

     

    一.通过Character Controller(角色控制器组件)

      1.SimpleMove

        public bool SimpleMove(Vector3 speed); 

          忽略y轴上的速度,返回值表示是否着地。

         CharacterController ch;
            //获取组件
            ch = GetComponent<CharacterController> ();
            //获取玩家的水平和竖直的输入
            Vector3    moveDir = new Vector3 (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
            //转换到世界坐标
            moveDir = transform.TransformDirection (moveDir);
            ch.SimpleMove (speed*moveDir);

      2.move

        public CollisionFlags Move(Vector3 motion);

        通过外力来移动控制器,并沿着碰撞体滑动,只受限于碰撞,不考虑重力影响。

      

    二.通过动画来移动,需要勾选Apply Root Motion

      1.BlendTree(1D)

        首先需要有一个创建一个BlendTree,这个BlendTree中需要有三个animation动画片段,外面有一个Idle动画,用于与BlendTree之间的切换,我们可以将这个BlendTree命名为Run,Run包含了三个动画片段,run,runLift,runRight(这里没有向后退的动画);

        接着需要声明两个参数,一个Speed: float,用于控制从Idle到Run,另一个为Direction:float,用于控制1D BlendTree的,runLift为-1,run为0,runRight为1,这里的参数基本就设置完成了。

        再就是Idle到Run之间的转换,Conditions设置为Speed,当Greater 0.1时候,切换到Run,less 0.1切换到Idle,

        最后就是需要在代码中实现的部分了,上代码(有点简陋。。。)

    void Update()
        {
            animator.SetFloat (hs.SpeedFloat,h*h+v*v);
            animator.SetFloat (hs.DirectionFLoat,h,DirectionDampTime,Time.deltaTime);
    
        }
  • 相关阅读:
    wmware虚拟机的克隆
    解决SecureCRT无法用非root账号登录ssh
    Docker容器操作
    Docker镜像操作
    Docker的安装和启动
    linux安装tomcat
    POJ 2456 Aggressive cows ( 二分搜索)
    POJ 1064 Cable master (二分查找)
    2008 APAC local onsites C Millionaire (动态规划,离散化思想)
    贿赂囚犯 Bribe the prisoners ( 动态规划+剪枝)
  • 原文地址:https://www.cnblogs.com/springword/p/6008822.html
Copyright © 2011-2022 走看看