简体   繁体   English

Unity 2D跳跃动画C#

[英]Unity 2D Jump Animation C#

I'm currently activating a trigger parameter to cycle the jump animation using: 我正在使用以下方法激活触发器参数以循环跳转动画:

isGrounded is my 'is player grounded bool', which I'm using to determine wether or not my player is allowed to jump. isGrounded是我的'是玩家接地布尔',我用来确定我的玩家是否被允许跳跃。 I'm using a child player object and using Physics2D.lineCast(myPlayer, myPlayerGround, playerMask) to do so. 我正在使用一个子播放器对象,并使用Physics2D.lineCast(myPlayer, myPlayerGround, playerMask)这样做。

I'm triggering the jump animation (using a trigger parameter to transfer to the jump animation from the run or idle, which are the only 2 other animations I'm using which currently work flawlessly) using the spacebar, the same way I tap in to the y axis jump velocity. 我正在触发跳转动画(使用触发器参数从运行或空闲转移到跳转动画,这是我正在使用的其他两个当前正在使用的动画完美无缺)使用空格键,就像我点击到y轴的跳跃速度。

I can't figure out a reliable way to reset the trigger. 我无法找到一种可靠的方法来重置触发器。 I tried resetting it if isGrounded returned true, but then I'm assuming I'm getting a false positive, as it will only trigger in the first place if isGrounded returns a true? 我尝试重置它,如果isGrounded返回true,但是我假设我得到了误报,因为它只会在第一个地方触发,如果isGrounded返回true? I also tried triggering the animation on by running a check to see if isGrounded returns a false, but if that's the case, the jump animation will play if I fall off a ledge, as well as actually jumping, which of course doesn't make sense. 我还尝试通过运行检查来触发动画,看看isGrounded返回false,但如果是这种情况,如果我从窗台上掉下来,以及实际跳跃,跳跃动画将会播放,这当然不会感。

I would put a couple of conditions, including the velocity direction and the isGrounded state. 我会提出几个条件,包括速度方向和isGrounded状态。 To reset the jump animation, you must be moving downward, and the isGrounded must be triggered. 要重置跳转动画,您必须向下移动,并且必须触发isGrounded。

For perfect results in these kind of situation I always do trust on Delegates. 为了在这种情况下取​​得完美的成绩,我始终相信代表们。 You can use delegate such as your ground will through the message if players did land. 如果玩家登陆,你可以通过消息使用代表,例如你的地面。 Here I gave a detailed implementation of exactly same scenario. 在这里,我给出了完全相同的场景的详细实现。 Have a look at my answer there. 看看我的答案。

You must add conditions to your animations. 您必须为动画添加条件。

Animator.SetBool("isTouched", isTouched);

When you set new value, your animation will be animated. 设置新值时,动画将被动画化。 Take a look at this tutorial. 看一下教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM