Godot buttons and collision shapes – perfectly adapt to image object (Godot 4)?

How can one get the size problem under control so that the collision shape of character bodies is perfectly adjusted and the same question again for buttons so that

you can't click outside of an image.

For the normal button example, I have a button and below it a TextureRect,

no matter if below or above, the texture is a png image where the background has been removed, however, it also reacts when I am in

click on the scaling area of ​​the image, ie where the non-existent background would be, which is not part of the object image.

1 vote, average: 1.00 out of 1 (1 rating, 1 votes, rated)
You need to be a registered member to rate this.
Loading...
Subscribe
Notify of
5 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Charmin
1 year ago

For a CharacterBody, use the CollisionPolygon2D to manually set and better adjust the shape.

For the button, set the “Click Mask” property at the TextureButton so that only certain areas can be clicked. Alternatively, check the alpha value of the clicked pixel when you click to only react to visible parts.

Charmin
1 year ago

Yes, I can! You can use a bitmap (eg a black-and-white image file) to generate a collision shape for a character body. This is particularly useful if you want an accurate collision for complex forms that can be easily defined manually.