Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Halflove |
Hey there! So I’m currently experimenting with GDScript and Godot alike and I’ve run into a bit of a wall that I can’t figure out how to resolve.
So I’m basically trying to make a scene for a tree that when a player walks into it’s Area2D node, a popup will display saying “this tree can be cut down”. Now at first I thought "well I’ll just check to see if a kinematicbody2D enters the tree’s Area2D that should work, but then I realized that this would cause some issues if I add other nodes/scenes later down the line that are also kinematicbody2D (I only want it to recognize the player).
So here is what I have so far:
Player’s script:
extends KinematicBody2D
class_name Player
var uid = self.get_instance_id()
Tree’s script:
extends Area2D
class_name ChopOakTree
var uid = self.get_instance_id()
var player = Player.new()
func _on_Choppable_Oak_Tree_body_entered(body: KinematicBody2D):
print("Oak Tree: ", uid)
print("Entered Body ", body.get_instance_id())
print("Player ", player.uid)
if(body.get_instance_id() == player.uid):
print("Works")`
Now I thought that would work, but for some reason the entered body (even though it is definitely the player) and the player instance id’s do not match:
Oak Tree: 1301
Entered Body 1306
Player 1302
Hopefully someone could point me in the right direction towards success with this task, thanks in advance
Thank you, I appreciate it
Halflove | 2021-06-13 13:41