godot - How to change the scene when a player collides with Node 2D? - Stack Overflow

I need to make it so that when the player collides with an object, the scene changes. But nothing happe

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744074922a4554221.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信