首页 文章

顺利的球员跳跃

提问于
浏览
1

我正在与Unity进行游戏,玩家拿起一个cookie然后玩家在y轴上跳跃 . 当球员跳跃时,他正在抽搐(非常) . 我希望跳跃,我希望看到那个球员顺利跳投 . 这是我的代码示例

void OnTriggerEnter2D(Collider2D other)
{
    if(other.gameObject.CompareTag("Player"))
    {
    player.velocity = new Vector2 (0, 0);
    player.AddForce(new Vector2(0,jumpHeight));
}

我测试了大约1000f的jumpHeight值 . 同样的问题是更高或更低的 Value .

更新:这是我的相机移动代码示例:

void Update () 
    {
        playerHeightY = player.position.y;
        float currentCameraHeight = transform.position.y;
        float newHeightOfCamera = Mathf.Lerp (currentCameraHeight, playerHeightY, Time.deltaTime * 10f);

        if (playerHeightY > currentCameraHeight) 
        {
            transform.position = new Vector3 (transform.position.x, newHeightOfCamera, transform.position.z);
        } 
}

谢谢和亲切的问候

1 回答

  • 1

    我刚刚将newHeightOfCamera值从10f提升到100f现在,玩家正在非常平稳地向上移动 . 我希望这篇文章对某人有所帮助 . 谢谢 :)

    void Update () 
        {
            playerHeightY = player.position.y;
            float currentCameraHeight = transform.position.y;
            float newHeightOfCamera = Mathf.Lerp (currentCameraHeight, playerHeightY, Time.deltaTime * 100f);
    
            if (playerHeightY > currentCameraHeight) 
            {
                transform.position = new Vector3 (transform.position.x, newHeightOfCamera, transform.position.z);
            } 
    }
    

相关问题