- Edited
Hello
I can't get an Area2D to respond to mouse input (enter, move, click etc.), if I add a CollisionPolygon2D in it in a script. Pickable, monitoring and monitorable are turned on for the area in the Inspector. I'm using Godot 2.1.4 stable official on Win 10.
My scene structure looks like this:
Node2D + Area2D
I have this script in the Area2D:
extends Area2D
var points = [
Vector2(0, -50),
Vector2(50, 50),
Vector2(-50, 50)]
var collision_polygon
func _ready():
collision_polygon = CollisionPolygon2D.new()
add_child(collision_polygon)
collision_polygon.set_polygon(points)
collision_polygon.set_trigger(true)
print(collision_polygon.get_polygon()) # Prints "[(0, -50), (50, 50), (-50, 50)]"
print(collision_polygon.get_collision_object_first_shape()) # Prints "-1"
print(collision_polygon.get_collision_object_last_shape()) # Prints "-1"
func _draw():
draw_colored_polygon(points, Color(1,0,0,1))
func _input_event(viewport, event, shape_idx):
print("mouse detected") # Doesn't get printed when mousing over the triangle.
It seems weird that the get_collision_object_X_shape() methods return -1. It sounds like the shapes aren't being created from the points.
Is it possible to get this to work somehow?