I'm trying to make a tank character for my game but I couldn't do the math of firing bullets from turret instead of center of the tank.
I tried some Stack Overflow solutions but I couldn't understand them correctly or they weren't related to my issue.
this.angle = (rotation in radians) + Math.PI / 2 var x = -40 * Math.sin(this.angle) - -40 * Math.cos(this.angle); var y = -40 * Math.cos(this.angle) + -40 * Math.sin(this.angle); turretX = turretX - x; turretY = turretY - y;
Now, as you can imagine, the position is always 40px wrong. That's expected since I try to change values of both x and y regardless of whether they're already correct or not.
How can I get the correct x, y?