Guns are 128x128 pixel frame, all of them has a different holding point, and a different firing point. The character has to be able to change guns real time, so these refference points has to change as well, so I can’t simply change sprites. Probably it can be solved via a traditional method used for 3d games but I am not very familiar about these as well. I can design a full gun setup, for each of them, but how can I change them and where should I store them? In my mind gun was a part of the character blueprint, should I set gun as it’s own blueprint?
3D games use skeletal meshes and sockets. In that scenario you would have a “handle” socket and a “muzzle” socket in order attach the gun mesh to the character and the muzzle VFX to the gun. I am not sure how 2D games handle those though.
Create a “gun” component in your character and make it able shoot like all your weapons based on some parameters like: is it automatic, fire rate, projectile, gun sprite, where do you fire from, where is it attached. Changing the weapon in this case would be just changing those parameters.
The data for the weapons depend on how many do you want and how would you prefer to edit that data. Since the data should be just parameters you feed the gun component they can be in structs in some data table, data assets or just object blueprint that are used as just as data holders.
This is only one approach from many and it might not be the best for your game. Just start building something and it will show.
I see, so for the major problem, I just have to set muzzle and handle coordinates based on the center and store them in a data table for each gun and change them as the gun changes. Pretty simple yeah, but which exact way should I do it? Is there a quick way to get coordinates from a center point and convert them to float for each vector, or I can just save it directly as a location or coordinate format?
Yes design the guns , each sprite has its own setup paper 2d is good for it, make data driven with data table. OnWeaponEquip select data asset and assign.
If you don’t want to use Paper2d You know the coordinates of the each gun.
DataStruct
- WeaponA
- SpriteAsset = SoftObjectRef
- AttachmentPoint = Vector2(x,y)
- MuzzlePoint = Vector2(x,y)
OnWeaponChange ->GetTableRow (WeaponA) → SetSpriteAsset (WeaponA ->SpriteAsset) ->TransformLocation(SpriteAsset) = AttachmentPoint
CurrentShootingLocation = GetLocalMuzzleOffset( WeaponA (MuzzlePoint -AttachmentPoint) )