Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 运动员动作协调,跳跃更流畅_C#_Unity3d - Fatal编程技术网

C# 运动员动作协调,跳跃更流畅

C# 运动员动作协调,跳跃更流畅,c#,unity3d,C#,Unity3d,我看到有人说,你应该在走完一个平台之后或者在你接触地板之前设置一个延迟计时器,因为这会让你的游戏感觉好多了!这是我以前试过的代码- using UnityEngine; using System.Collections; public class example : MonoBehaviour { //Variables public float speed = 6.0F; public float jumpSpeed = 8.0F; publi

我看到有人说,你应该在走完一个平台之后或者在你接触地板之前设置一个延迟计时器,因为这会让你的游戏感觉好多了!这是我以前试过的代码-

 using UnityEngine;
 using System.Collections;

 public class example : MonoBehaviour {
     //Variables
     public float speed = 6.0F;
     public float jumpSpeed = 8.0F; 
     public float gravity = 20.0F;
     private Vector3 moveDirection = Vector3.zero;

     void Update() {
         CharacterController controller = GetComponent<CharacterController>();
         // is the controller on the ground?
         if (controller.isGrounded) {
             //Feed moveDirection with input.
             moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
             moveDirection = transform.TransformDirection(moveDirection);
             //Multiply it by speed.
             moveDirection *= speed;
             //Jumping
             if (Input.GetButton("Jump"))
                 moveDirection.y = jumpSpeed;

         }
         //Applying gravity to the controller
         moveDirection.y -= gravity * Time.deltaTime;
         //Making the character move
         controller.Move(moveDirection * Time.deltaTime);
     }
 }
使用UnityEngine;
使用系统集合;
公共课示例:单一行为{
//变数
公共浮子速度=6.0F;
公共浮子跳跃速度=8.0F;
公共浮子重力=20.0F;
专用矢量3移动方向=矢量3.0;
无效更新(){
CharacterController=GetComponent();
//控制器在地面上吗?
if(controller.isground){
//输入的进给方向。
moveDirection=新矢量3(Input.GetAxis(“水平”),0,Input.GetAxis(“垂直”);
moveDirection=transform.TransformDirection(moveDirection);
//乘以速度。
移动方向*=速度;
//跳跃
if(Input.GetButton(“跳转”))
移动方向。y=跳跃速度;
}
//向控制器应用重力
moveDirection.y-=重力*时间增量;
//使角色移动
控制器移动(移动方向*时间增量);
}
}

如果你想让玩家在你触地之前跳起来,只需使用自动倒计时的计时器。更改它,使您在按下跳转按钮时不会跳转,而是重置计时器。以下是一个例子:

public float jumpRememberTime = 0.2f; 
private float jumpRememberTimer; 

private void Update()
{
    jumpRememberTimer -= Time.deltaTime; 

    if (Input.GetButtonDown ("Jump"))   
        jumpRememberTimer = jumpRememberTime; 

    if (jumpRememberTimer > 0f && controller.isGrounded)
    {
        moveDirection.y = jumpSpeed; // jump
    }
}
为了让玩家在离开平台后立即跳起,你还需要一个计时器。这就是所谓的郊狼时代。当玩家离开平台时,你使用计时器并使其倒计时。这是实现此功能后的代码

public float jumpRememberTime = 0.2f; 
private float jumpRememberTimer; 

public float groundedRememberTime = 0.2f; 
private float groundedRememberTimer = 0f;

private void Update()
{
    jumpRememberTimer -= Time.deltaTime; 

    if (Input.GetButtonDown ("Jump"))   
        jumpRememberTimer = jumpRememberTime; 

    if (isGrounded)
        groundedRememberTimer = groundedRememberTime; 
    else
        groundedRememberTimer -= Time.deltaTime; 

    if (jumpRememberTimer > 0f && groundedRememberTimer > 0f)
    {
        moveDirection.y = jumpSpeed; // jump
    }
}

你的问题是什么?我怎样才能让动作更流畅呢!