Question
I’m having having an interesting problem where whenever I try to refer to a player (which is a CharacterBody2D) it returns multiple values. Here are the values a player is returning:
Player1:<CharacterBody2D#42765124888>
<EncodedObjectAsID#-9223371976037366478>
This is throwing a wrench in my plans, because checking the groups of a CharacterBody2D is fine (and my current intention), but the game crashes if you try to check the groups of an EncodedObjectAsID!
Here is the code on the player when they click the button to shoot:
func shoot():
var new_projectile = projectile.instantiate()
new_projectile.player = self
get_parent().add_child(new_projectile, true)
new_projectile.position = self.position
if $Sprite2D.scale.x > 0:
new_projectile.set_linear_velocity(Vector2(3000, 0))
else:
new_projectile.set_linear_velocity(Vector2(-3000, 0))
And here is the code of the bullet itself:
func _on_area_2d_area_entered(area):
if area.is_in_group("hurt_box") and area.get_parent() != self.player:
var direction = self.linear_velocity.x
#var direction = facing
var target = area.get_parent()
get_parent().get_shot.rpc(target, direction)
queue_free()
Currently, all the function of the get_shot() function is just print(target), which gave the values I posted way above.
Why is this happening? How can I only get the value I expect when trying to reference a player (their CharacterBody2D node)?