Rotating an offset position in 2D space around an origin point

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.

this could be just the Angle can be minus less than -360 and more than 360.0
try math absolute the direction angle first then fmod 360.0 it

Sorry, it’s taken me a bit to get back to this, but I’m afraid I don’t really follow.

Given the entity’s transform and an angle, I can get the absolute value of the direction

posOffset = Mathf.Abs(direction)

but I don’t understand the second part of your response. What should I do to this absolute value to rotate it? Thank you!

fmod it, basically float mod operation of 360.0

Hi,
you need to rotate the local offset before adding the position

Salud!