Triggerin a CollisionPolygon2D...

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Syl

Here’s my attempt at making a click in the polygon trigger the changin scene, but the animation start at a click anywhere on the screen… How’s that?.

And my script:

If you could help…

:bust_in_silhouette: Reply From: 2D

Your code isn’t selecting for events only in your Bodypoly, but rather is accepting the mouse click from anywhere.

Utilize the CollisionObject2d signal “_onArea2D_input_event” in the Area2D node by connecting it in the editor to your Bodypoly node and override the function like this:

func _on_Area2D_input_event( viewport, event, shape_idx ):
	if event is InputEventMouseButton:
		if event.get_button_index() == BUTTON_LEFT and event.is_pressed():
			get_node("AnimationPlayer").play("change1")

:smiley: That works! A BIG thxs!

Syl | 2018-03-03 18:15