0 votes

I have a C# script attached to MeshInstance2d object. Script generates an Hexagonal Arraymesh with uv-s. How can i detect if a mouse is hovering one of these hexagons? As everything is generated within code, i cant use editor methods to generate collision shapes and what not, so everything that needs to be generated, must be generated within code.

I understand that i need a collision shape, but how do i make it and where to i but it?

in Engine by (12 points)

1 Answer

0 votes

Assuming your node won't move, add a Area2D to it with input_pickable set to true (so it will receive input events), and then a CollisionPolygon2D as child. You can then generate the points of the polygon into a hexagon : https://docs.godotengine.org/en/stable/classes/class_collisionpolygon2d.html
It works the same in C# or GDScript.

You may have to learn how collisions work in Godot 2D: https://docs.godotengine.org/en/stable/tutorials/physics/index.html

by (27,766 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.