zoukankan      html  css  js  c++  java
  • [Unity3D] 人物角色跳跃(动画跳跃&刚体跳跃)

    方法一:

    添加刚体,使用刚体位移实现跳跃

     1 public class HeroMove : MonoBehaviour {
     2   //---跳起的力量
     3   public float JumpGravity = 500f;
     4   //---刚体
     5   public Rigidbody rg; 
     6   
     7   
     8   private void Start() {
     9     //---查找刚体组件
    10 
    11     rg = this.GetComponent<Rigidbody>();
    12   }
    13 
    14   
    15 
    16   private void Update(){
    17 
    18     //---判断是否按下空格
    19     if (Input.GetKeyDown(KeyCode.Space) ){
    20 
    21     //---为刚体的Y赋值一个新的高度,这个高度为跳跃重力,向上的力
    22     rg.velocity = new Vector3(rg.velocity.x, JumpGravity *     
    23            Time.deltaTime,rg.velocity.z);
    24   }
    25 
    26 }
    View Code

    方法二:

    使用动画效果位移跳跃(缺点,不能控制高度)

     1 public class HeroMove : MonoBehaviour {
     2 
     3     //---动画组件应用
     4     private Animator animt;
     5     //---跳跃动画名,可以是一个或者多个[]
     6     public string JumpName;
     7 
     8   private void Start() {
     9     //---查找动画组件赋值
    10             animt = this.GetComponent<Animator>();
    11 
    12   }
    13 
    14   
    15 
    16   private void Update(){
    17 
    18     //---判断是否按下空格
    19     if (Input.GetKeyDown(KeyCode.Space) ){
    20                //---播放动画跳跃
    21                 animt.SetBool("JumpName",true);
    22     
    23   }
    24 
    25 }  
    View Code
    时间若流水,恍惚间逝去
  • 相关阅读:
    一般索引
    微信小程序扫码
    微信小程序
    PHPStudy设置局域网访问
    phpstudy
    爱番番
    织梦栏目url的seo处理
    织梦dedecms网站迁移搬家图文教程
    打开存储过程中的代码目录(转)
    正在载入
  • 原文地址:https://www.cnblogs.com/alanshreck/p/13682174.html
Copyright © 2011-2022 走看看