我正在尝试设置所有僵化的'速度为0,然后是以前的速度

发布于 2025-01-30 20:03:57 字数 1843 浏览 4 评论 0原文

因此,在过去的几个小时中,我一直在尝试创建一个暂停菜单。但是,我无法弄清楚如何阻止刚体移动。如果有一种方法可以立即停止所有僵化的机构,请告诉我,如果没有,我可以将其设置在每个脚本上,都用刚性的身体设置。到目前为止,这是我的代码:

extends Position3D
onready var charCamera = get_viewport().get_camera()
##var direction = Camera.global_transform.basis.get_euler()

signal spawned(spawn)

export(PackedScene) var spawnling_scene
var linear_velocity_on_pause = 0
var not_paused_anymore = false
var paused = false
#var Popup1 = self.get_parent().get_parent().get_parent().get_node("Popup")
func _physics_process(_delta):
    
    if self.get_parent().get_parent().get_parent().get_node("Popup").visible == false:
        if Input.is_action_pressed("leftClick"):
            spawn()
        if paused == true:
            not_paused_anymore = true
            paused = false
        
    if self.get_parent().get_parent().get_parent().get_node("Popup").visible == true:
        linear_velocity_on_pause = spawnling_scene.instance().linear_velocity
        paused = true
        spawnling_scene.instance().set_mode(1)
        spawnling_scene.instance().linear_velocity = get_parent().get_parent().get_parent().get_node("LinearVelocityOf0").linear_velocity
    
    if not_paused_anymore == true:
        spawnling_scene.instance().set_mode(0)
        
        spawnling_scene.instance().linear_velocity = linear_velocity_on_pause
        not_paused_anymore = false

func spawn():
    var spawnling = spawnling_scene.instance()
    spawnling.linear_velocity = charCamera.global_transform.basis.z * -100
    #spawnling.global_transform.basis = charCamera.global_transform.basis
    add_child(spawnling)
    spawnling.set_as_toplevel(true)
    emit_signal("spawned", spawnling)
    ##insert pause system
    return spawnling

##var spawnling = spawnling_scene.instance()
##  
##  add_child(spawnling)
##  spawnling.set_as_toplevel(true)

So I have been trying to create a pause menu for the past few hours. However, I cannot figure out how to stop the rigidbodies from moving. If there is a way to stop all rigidbodies at once, please tell me, if not, I can set it to each and every script with a rigid body. Here is my code so far:

extends Position3D
onready var charCamera = get_viewport().get_camera()
##var direction = Camera.global_transform.basis.get_euler()

signal spawned(spawn)

export(PackedScene) var spawnling_scene
var linear_velocity_on_pause = 0
var not_paused_anymore = false
var paused = false
#var Popup1 = self.get_parent().get_parent().get_parent().get_node("Popup")
func _physics_process(_delta):
    
    if self.get_parent().get_parent().get_parent().get_node("Popup").visible == false:
        if Input.is_action_pressed("leftClick"):
            spawn()
        if paused == true:
            not_paused_anymore = true
            paused = false
        
    if self.get_parent().get_parent().get_parent().get_node("Popup").visible == true:
        linear_velocity_on_pause = spawnling_scene.instance().linear_velocity
        paused = true
        spawnling_scene.instance().set_mode(1)
        spawnling_scene.instance().linear_velocity = get_parent().get_parent().get_parent().get_node("LinearVelocityOf0").linear_velocity
    
    if not_paused_anymore == true:
        spawnling_scene.instance().set_mode(0)
        
        spawnling_scene.instance().linear_velocity = linear_velocity_on_pause
        not_paused_anymore = false

func spawn():
    var spawnling = spawnling_scene.instance()
    spawnling.linear_velocity = charCamera.global_transform.basis.z * -100
    #spawnling.global_transform.basis = charCamera.global_transform.basis
    add_child(spawnling)
    spawnling.set_as_toplevel(true)
    emit_signal("spawned", spawnling)
    ##insert pause system
    return spawnling

##var spawnling = spawnling_scene.instance()
##  
##  add_child(spawnling)
##  spawnling.set_as_toplevel(true)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

伴梦长久 2025-02-06 20:03:57

我不是在回答如何将所有刚体的速度设置为零的问题。


您想制作暂停菜单,这就是您应该知道的:

如果 您可以使用这样的使用来暂停:

get_tree().paused = true

和恢复:

get_tree().paused = false

请参阅

哪个节点 s在get_tree()。​​暂停设置为true依赖其pape_mode属性时。默认情况下,它们都将停止,但是如果您将其pape_mode设置为pape_mode_process,当get_tree()时,他们将继续工作。 true。这就是您要使用Node构成您的暂停菜单UI的方法。


但是,该系统不会暂停着色器。他们的时间将继续打勾。如果要“冻结”着色器,则可以将0设置为按这样的时间缩放:

VisualServer.set_shader_time_scale(0)

将其设置为1,以定为正常速度:

VisualServer.set_shader_time_scale(0)

您可以设置其他值以使它们放慢速度或加速。


说到放缓和加快。如果您想在游戏的其余部分(不仅仅是着色器)这样做,则可以使用Engine.time_scale。而且,如果您不想受到影响,则必须在os类中使用时间函数编写它。

I'm not answering the question of how to set the velocity of all rigid bodies to zero.


If you want to make a pause menu, this is what you should know:

Godot has a puse system, which you can use like this to pause:

get_tree().paused = true

And to resume:

get_tree().paused = false

See Pausing Games.

Which Nodes gets to execute when get_tree().paused is set to true depend on their pause_mode property. By default they will all stop, but if you set their pause_mode to PAUSE_MODE_PROCESS they will continue to work when get_tree().paused is set to true. And that is what you want to do with the Node that make up your pause menu UI.


However, that system will not pause shaders. Their TIME will continue to tick. If you want to "freeze" shaders you can set a 0 to their time scaling like this:

VisualServer.set_shader_time_scale(0)

Set it to 1 for normal speed:

VisualServer.set_shader_time_scale(0)

And you can set other values to have them slow down or speed up.


Speaking of slow down and speed up. If you want to do that for the rest of the game (not just shaders), you can use Engine.time_scale. And if there is some timing that you don't want to be affected, you would have to write it using the time functions in the OS class.

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