admin管理员组

文章数量:1357276

I need to make it so that when the player collides with an object, the scene changes. But nothing happens during collision. Could you please tell me how to solve this problem?

extends Node2D

func _on_body_entered(body):
    if body.name == "Player":
        get_tree().change_scene_to_file("res://level1.tscn")

Here's a screenshot

I need to make it so that when the player collides with an object, the scene changes. But nothing happens during collision. Could you please tell me how to solve this problem?

extends Node2D

func _on_body_entered(body):
    if body.name == "Player":
        get_tree().change_scene_to_file("res://level1.tscn")

Here's a screenshot

Share Improve this question asked Mar 27 at 18:02 Sin nombreSin nombre 92 bronze badges 3
  • At a glance, it seems like the if statement isnt triggering. On the first line of the function, if you print body.name, what is output on a collision with the player? – Jonathan F. Commented Mar 27 at 19:39
  • player.gd:47 @ _physics_process(): Parameter "body get_space() is null. – Sin nombre Commented Mar 28 at 12:54
  • So if you try to print the name, the program errors? Was it erroring before adding the print statement? To be explicit, my previous recommendation was to add print(body.name) to the line before if body.name ==.... – Jonathan F. Commented Mar 28 at 13:26
Add a comment  | 

1 Answer 1

Reset to default 0

I think I know the problem. Select the detector object (object that sends the signal) in your node tree. Click on Node, and you will see the options Signals and Groups. Click Signals, and you will see the list of signals. Double click any of them to link it to your script.

本文标签: godotHow to change the scene when a player collides with Node 2DStack Overflow