Godot Version
Godot version 4.2.1
Question
Hello all.
In my game, I can fire a projectile from the player’s origin point. I would like to offset this position from the origin, and would like this offset position to rotate. The direction the projectile travels rotates separately from the player’s sprite. The shooter object is given a list of offset positions from which to shoot from, so there can be 2, 3, 4, or more spawn points distributed around the player. My issue is that currently I can’t figure out how to rotate the offset position. Any of my attempts to rotate the offset position have resulted in the spawn point being far away from the position it should be. With that in mind, how do I rotate an offset position in 2D space around a center pivot?
Currently I am using this code:
Vector2 posOffset = user.GlobalPosition + Offset;
posOffset = posOffset.Rotated(direction.Angle());
With Offset being the Vector2 of where the bullet will spawn from around the player, and Direction being the direction the player is aiming. I’ve also tried
Vector2 posOffset = user.GlobalPosition + new Vector2(Mathf.Sin(direction.Angle()), Mathf.Cos(direction.Angle())) * Offset;
This results in the spawn point remaining over the player, but does not rotate the spawn point around the origin. Rather, if the offset is set to (0,1), it will move the offset vertically, with more extreme rotations making the offset further up and down.
Below I’ve drawn a diagram of what problem I’d like to solve
Thank you for your help.