如何更改脚本中过渡节点上的 XFade?
我目前正在学习 Godot,我的教科书似乎有点过时,因为它仍然使用已弃用的 AnimationTreePlayer。所以我必须自己弄清楚AnimationTree。本课的练习讨论了当玩家按下“向上”键时将过渡节点的 XFade 更改为随机值,但我一生都无法弄清楚如何做到这一点。我在文档中看到 AnimationNodeTransition 有一个 set_cross_fade_time(value) 方法,但我如何获取它?我如何访问脚本中的转换节点?我尝试过 $AnimationTree/Transition 和 $AnimationTree["parameters/Transition"] 之类的东西,但我尝试过的都不起作用。
我的脚本当前位于根节点上,节点树如下所示:
- Sprite [script is here]
- 动画播放器
- 动画树
I'm currently learning Godot and my textbook seems to be a bit out of date as it still uses the deprecated AnimationTreePlayer. So I've had to figure out AnimationTree on my own. The exercise for this lesson talks about changing the XFade for the transition node to a random value when the player presses the "up" key but I cannot for the life of me figure out how to do it. I see in the documentation that AnimationNodeTransition has a set_cross_fade_time(value) method but how do I get to it? How do I even access the tranisition node in the script? I've tried things like $AnimationTree/Transition and $AnimationTree["parameters/Transition"] but nothing I've tried works.
My script is currently on the root node and the node tree looks like this:
- Sprite [script is here]
- AnimationPlayer
- AnimationTree
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您有一个
AnimationTree
,并且在anim_player
属性上设置了AnimationPlayer
。AnimationTree
的tree_root
是一个AnimationNodeBlendTree
,其中 - 在其他节点中 - 您有一个AnimationNodeTransition
。如您所知,我们可以获得
AnimationTree
的一些“参数”,它们应该出现在检查器面板中。您应该在那里找到这个:其中
"Transition"
是AnimationNodeBlendTree
中节点的名称。但没有xfade_time
参数。相反,我们将像这样获得
AnimationTree
的根(换句话说,AnimationNodeBlendTree
):然后我们可以像这样获得节点:
顺便说一下,如果将
"/node"
更改为"/position"
,您将获得一个Vector2
,其中包含节点在编辑器上的位置。所以,假设我们想要一个名为“Transition”,即我们的
AnimationNodeTransition
。我们这样做:最后我们可以访问
xfade_time
。你说的设置一个随机值?应该这样做:或者作为一行:
请注意,
xfade_time
的值是过渡的秒数。因此,设置120
将为您提供两分钟的过渡时间。Let us say you have your
AnimationTree
with theAnimationPlayer
set on theanim_player
property. And thetree_root
of theAnimationTree
is anAnimationNodeBlendTree
, where - among other nodes - you have anAnimationNodeTransition
.As you are aware, we can get some "paramters" of the
AnimationTree
, they should appear in the Inspector Panel. And there you should find this one:Where
"Transition"
is the name of the node in theAnimationNodeBlendTree
. But there isn't a parameter for thexfade_time
.Instead we will get the root of the
AnimationTree
(in other words, theAnimationNodeBlendTree
) like this:Then we can get the nodes like this:
By the way, if you change
"/node"
to"/position"
you get aVector2
with the position of the node on the editor.So, let us say we want a node called "Transition", which is our
AnimationNodeTransition
. We do this:And finally we can access
xfade_time
. Set a random value you said? This should do:Or as a one line:
Be aware that the value of
xfade_time
is the number of seconds for the transition. So setting120
give you a two minutes transition.