首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于球员运动控制的C#单位双跳编码

用于球员运动控制的C#单位双跳编码
EN

Stack Overflow用户
提问于 2013-09-25 18:36:36
回答 1查看 14.8K关注 0票数 0
代码语言:javascript
复制
using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour 
{
public float speed          = 3.0f;
public float jumpSpeed          = 200.0f;
public bool grounded            = true;
public float time           = 4.0f;     



// Use this for initialization
void Start () 
{

}

// Update is called once per frame
void FixedUpdate () 
{
    Vector3 x = Input.GetAxis("Horizontal")* transform.right * Time.deltaTime *      speed;

    if (time <= 2)
    {
    if(Input.GetButtonDown("Jump"))
        {
                Jump();
        }

    }

    transform.Translate(x);

    //Restrict Rotation upon jumping of player object
    transform.rotation = Quaternion.LookRotation(Vector3.forward);


}
void Jump()
    {
        if (grounded == true)
        {
            rigidbody.AddForce(Vector3.up* jumpSpeed);


            grounded = false;
        }

    }
void OnCollisionEnter (Collision hit)
{
    grounded = true;
    // check message upon collition for functionality working of code.
    Debug.Log ("I am colliding with something");
}

}

应该在哪里,什么类型的编码可以让它在回到地面之前跳两次?

有一个物体上面有精灵纸,我已经获得了基于物理引擎的约束运动和正常跳跃的统一。但我希望运动更有活力,只在没有接地的情况下跳两次,并在一定的时间范围内跳跃两次,就像在地面休息时在几毫秒间隔内按下跳跃按钮来重置位置一样。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-25 18:45:12

这应该能起到作用:

代码语言:javascript
复制
private bool dblJump = true;

void Jump()
{
    if (grounded == true)
    {
        rigidbody.AddForce(Vector3.up* jumpSpeed);

        grounded = false;
    } 
    else if (!grounded && dblJump)
    {
        rigidbody.AddForce(Vector3.up* jumpSpeed);

        dblJump = false;
    }

}

void OnCollisionEnter (Collision hit)
{
    grounded = true;
    dblJump = true;
    // check message upon collition for functionality working of code.
    Debug.Log ("I am colliding with something");
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19002590

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档