I'm not sure if this works right but you might be able to simply multiply the difference between the two origins against the sin() and tan().

Example: newbullet.shape.setPosition(sprite.getPosition().x+(32*cos(angle)),sprite.getPosition().y);

EDIT: My mistake. I guess that doesn't work right. I think i'm close tho.

If you add cos on the x, then you need to add sin on the y.

newbullet.shape.setPosition(sprite.getPosition().x+(32*cos(angle)),sprite.getPosition().y+(32*sin(angle)));

If i do:

bullet.setPosition(weaponSpr.getPosition().x + (76 * cos(gunAngle)), weaponSpr.getPosition().y + (76 * sin(gunAngle)));

It works and its cool, but the bullets spawn a bit below the barrel which is very noticable.

I did 76 because it makes the bullets spawn exactly at the end of the barrel, i'm not sure why since i improvised and put the desired weapon sprite x origin which is 32, multiplied it by 2 and then added the bullets x origin.

Can somebody explain why i needed to put 76 instead of 32 (which is the right side of my sprite since my image is 32x16) + weapon x origin?

Also it seems like if i put a different number for the sin calculation, the positioning is off.

Since the bullets spawn a little bit below the barrel, i thought i'd just change the sin calculation like:

bullet.setPosition(weaponSpr.getPosition().x + (76 * cos(gunAngle)), weaponSpr.getPosition().y + (20 * sin(gunAngle)));

which is the same formula as i did for x (put the desired y origin which is 8, multiplied it by 2 and then added the bullets x origin)

Im clearly very, very off, and i'm just taking blind guesses because i don't even know why i needed to apply the calculations in that formula.

Can somebody break down the formula used {bullet.setPosition(weaponSpr.getPosition().x + (76 * cos(gunAngle)), weaponSpr.getPosition().y + (76 * sin(gunAngle)))} so i can, know how it works?

From what i understand i calculate x and y of my rotation angle by using sin and cos, but why am i multiplying 76 by that x and y to change the origin?

I don't want to just copy paste things and move on, i want to learn!

EDIT: I just understood why i had to multiply my desired origin by 2, im a dummy

I forgot that i changed the scale of my weapon to 2,2 so i had to multiply the origin by that scale.

But still, why when i want my bulltes spawn at the y origin of 8 of my weapon, i can't do 8 x scale + bullets y origin? Why does it have to be 76 like in x, for it to not act weird and spawn the bullets very off?