|
|
|
 |
Reply From: |
kidscancode |
Use an Area2D with a CollisionShape2D set to “Circle”. Area2D has input capability - connect its input_event
signal, and check for mouse click events.
Next, measure the distance from the click position to the area’s position (the center of the circle), and assign your points.
func input_event(viewport, event, shape_index):
if event is InputEventMouseButton and event.pressed:
var distance_from_center = position.distance_to(event.position)
Alternatively, you could add multiple CollisionShape2D circles of varying radius, and use the shape_index
property to see which one was clicked, using that to assign points.
Thanks for your answer, I am getting the distance from the center! Amazing
Maybe you know the syntax of getting the center? Because I want to assign some points to the very center of the Area2D. var center = ?
Thanks in advance!
HashTag | 2020-03-06 08:00
The center of the collision shape is its position
. But this will probably be (0, 0)
if you call it on the collision shape since it’s relative to the parent. Use the area’s position
for that. Or if you need global coordinates, global_position
.
kidscancode | 2020-03-06 17:30
I see, Thanks a lot for your time explaining it to me! Have a nice weekend mate
HashTag | 2020-03-07 22:40
Sorry to disturb you, but maybe you could help me with another issue? I need dynamic “Sprite” with the “aim projectile” attached to one of his arms and after every click on the target “aim projectile” the “Sprite” would change his posture together with the placement of target attached to his arm. My first question would be, how could I achieve such “Dynamic” sprite and how could I attached my already created and working “Aim projectile”. I hope you are not to busy and will be able to help me out.
EXAMPLE — Imgur: The magic of the Internet
HashTag | 2020-03-09 15:33