Changing collision shape

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

Dear All,

I planned to make a weapon class which is should be instanced by the type of weapon.
It has a dictionary with the weapon names and those attributes. One of attributes is its sprite texture. So I managed to instance an appropriate type weapon in runtime, but i have trouble to set its collision shape.
Is there any way to set the shape from a texture mask? So I dream somethink like this:
for weapon1 collisionshape2d.set_shape(“res://collisionShapeMask1.png”) and for weapon2 collisionshape2d.set_shape(“res://collisionShapeMask2.png”)

Or other idea is I create a lot of collisionshape2d, set its form that reflect the appropriate weapon form and enable/disable in runtime. However it does not seem to nice.

Or should I go with the rookie solution? Make a scene for all weapons and turn enable(show)/disable(hide) those i would like to use?

thank you very much

:bust_in_silhouette: Reply From: BraindeadBZH

I think a good solution would be to use inheritance et load the correct weapon at runtime.