[英]Godot Viewport Node won't move with Parent Node
I am trying to have a Sprite 3D have a Viewport texture and I set up my Nodes like this:我正在尝试让 Sprite 3D 具有视口纹理,并且我这样设置我的节点: When I added Portal1 to another scene and moved it, the everything moved except the Viewport Node and Everything under it: Before:当我将 Portal1 添加到另一个场景并移动它时,除了视口节点及其下的所有内容外,所有内容都移动了:之前: After:后:
As you can see the Camera didn't move and I figured out it's because the Viewport didn't move.如您所见,相机没有移动,我发现这是因为视口没有移动。 I have tried multiple combinations and nothing works.我尝试了多种组合,但没有任何效果。 How can I get the Viewport node to move with the Parent?如何让 Viewport 节点随 Parent 一起移动?
There is no way to structure the scene tree that will do what you want.无法构建将执行您想要的操作的场景树。 The reason being that the Viewport
is the root of the transformations.原因是Viewport
是转换的根源。 The Viewport
itself does not have a transformation (so it does not makes sense to speak of the moving the Viewport
), and Godot does not resolve transformations pass a Viewport
. Viewport
本身没有转换(所以说移动Viewport
是没有意义的),并且 Godot 不会解析传递给Viewport
的转换。
What you can do is have the your scene root copy its global_transform
.你可以做的是让你的场景根复制它的global_transform
。 Something like this (if it is intended to be moving all the time):像这样的东西(如果它打算一直移动):
extends Spatial
onready var root := $Viewport/Root as Spatial
func _process(_delta: float) -> void:
root.global_transform = global_transform
Or like this (which is better if it rarely moves):或者像这样(如果它很少移动则更好):
extends Spatial
onready var root := $Viewport/Root as Spatial
func _ready() -> void:
set_notify_transform(true)
func _notification(what: int) -> void:
if what == NOTIFICATION_TRANSFORM_CHANGED:
root.global_transform = global_transform
And you can make it a tool
script if you want it to work on the editor.如果你想让它在编辑器上工作,你可以把它做成一个tool
脚本。 Be aware that you will need to reload the scene in the editor for it to begin working.请注意,您需要在编辑器中重新加载场景才能开始工作。
With a scene tree something like this:使用这样的场景树:
Portal
├ Viewport
│ └ Root
│ └ Camera
└ Sprite3D
With the script attached to Portal
.将脚本附加到Portal
。
Note that I'm not copying the global_transform
to the Camera
but to a new Node
which I called Root
so you can still move the Camera
relative to it.请注意,我没有将global_transform
复制到Camera
,而是复制到一个我称为Root
的新Node
,因此您仍然可以相对于它移动Camera
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.