如何更改脚本中过渡节点上的 XFade?

发布于 2025-01-10 02:46:34 字数 439 浏览 3 评论 0原文

我目前正在学习 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

錯遇了你 2025-01-17 02:46:34

假设您有一个 AnimationTree,并且在 anim_player 属性上设置了 AnimationPlayerAnimationTreetree_root 是一个 AnimationNodeBlendTree,其中 - 在其他节点中 - 您有一个 AnimationNodeTransition


如您所知,我们可以获得AnimationTree的一些“参数”,它们应该出现在检查器面板中。您应该在那里找到这个:

$AnimationTree.get("parameters/Transition/current")

其中 "Transition"AnimationNodeBlendTree 中节点的名称。但没有 xfade_time 参数。


相反,我们将像这样获得 AnimationTree 的根(换句话说,AnimationNodeBlendTree):

var blend_tree := $AnimationTree.tree_root as AnimationNodeBlendTree

然后我们可以像这样获得节点:

var blend_tree := $AnimationTree.tree_root as AnimationNodeBlendTree
var node := blend_tree.get("nodes/NodeName/node")

顺便说一下,如果将 "/node" 更改为 "/position",您将获得一个 Vector2,其中包含节点在编辑器上的位置。

所以,假设我们想要一个名为“Transition”,即我们的AnimationNodeTransition。我们这样做:

var blend_tree := $AnimationTree.tree_root as AnimationNodeBlendTree
var transition := blend_tree.get("nodes/Transition/node") as AnimationNodeTransition

最后我们可以访问xfade_time。你说的设置一个随机值?应该这样做:

var blend_tree := $AnimationTree.tree_root as AnimationNodeBlendTree
var transition := blend_tree.get("nodes/Transition/node") as AnimationNodeTransition
transition.xfade_time = rand_range(0.0, 120.0)

或者作为一行:

$AnimationTree.tree_root.get("nodes/Transition/node").xfade_time = rand_range(0.0, 120.0)

请注意,xfade_time 的值是过渡的秒数。因此,设置 120 将为您提供两分钟的过渡时间。

Let us say you have your AnimationTree with the AnimationPlayer set on the anim_player property. And the tree_root of the AnimationTree is an AnimationNodeBlendTree, where - among other nodes - you have an AnimationNodeTransition.


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:

$AnimationTree.get("parameters/Transition/current")

Where "Transition" is the name of the node in the AnimationNodeBlendTree. But there isn't a parameter for the xfade_time.


Instead we will get the root of the AnimationTree (in other words, the AnimationNodeBlendTree) like this:

var blend_tree := $AnimationTree.tree_root as AnimationNodeBlendTree

Then we can get the nodes like this:

var blend_tree := $AnimationTree.tree_root as AnimationNodeBlendTree
var node := blend_tree.get("nodes/NodeName/node")

By the way, if you change "/node" to "/position" you get a Vector2 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:

var blend_tree := $AnimationTree.tree_root as AnimationNodeBlendTree
var transition := blend_tree.get("nodes/Transition/node") as AnimationNodeTransition

And finally we can access xfade_time. Set a random value you said? This should do:

var blend_tree := $AnimationTree.tree_root as AnimationNodeBlendTree
var transition := blend_tree.get("nodes/Transition/node") as AnimationNodeTransition
transition.xfade_time = rand_range(0.0, 120.0)

Or as a one line:

$AnimationTree.tree_root.get("nodes/Transition/node").xfade_time = rand_range(0.0, 120.0)

Be aware that the value of xfade_time is the number of seconds for the transition. So setting 120 give you a two minutes transition.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文