0 votes

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.setshape("res://collisionShapeMask1.png") and for weapon2 collisionshape2d.setshape("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

in Engine by (12 points)

1 Answer

0 votes

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

by (1,045 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.