创建平滑跳跃动画

问题描述 投票:0回答:1

我有一些基本的跳转代码。玩家按下空格键后,它将开始跳跃,并且他们的jumpCount将设置为20。jumpCount与玩家的y一起递减,直到达到-20。此代码的主要问题是,玩家跳下后,每次到达地面后,最终收拢的姿势都会稍微降低一些。

y = 100
jumpCount = 20

while True:
    if keys[pygame.K_SPACE]:
        isJump = True

    if isJump:
        if jumpCount >= -20:
            neg = 1 
            if jumpCount < 0:  
                neg = -1

            y -= (jumpCount ** 2) * 0.05 * neg
            jumpCount -= 1

        else:
            jumpCount = 20
            isJump = False
python game-physics
1个回答
0
投票

问题是播放器跳了21次(jumpCount201918...0),但是跳了20次(jumpCount ]为-1-2-3...-20)。您应该使它们相等。

© www.soinside.com 2019 - 2024. All rights reserved.