+1 vote

I have a `Node2D` "Asteroid" that I want to rotate around specific `Vector2`.
In my case, the Asteroid gets spawned randomly on the map. I want to rotate it around the center of my map, in my case `Vector2(mapSize / 2, mapSize / 2)`

How can I do this?

In Unity they had something like "RotateAround" but it seems this is not the case in Godot. I'm really bad in maths and don't know how to work with `sin` and `cos`

Godot version 3.2.3
in Engine

Have you considered making your map from `-map_size / 2` to `map_size / 2` instead of `0` to `map_size`? Then `(0, 0)` would be the center.

what i usually do in cases like that is parent to a pivot(position2D) and rotate the pivot.

Here is a very basic solution :

``````extends Node2D
var angle = 0
var rotation_speed = 1

var center

# Called when the node enters the scene tree for the first time.
center = \$Sprite.position

func _process(delta):
angle = lerp(angle, deg2rad(360), rotation_speed * delta)
var coord = (Vector2(cos(angle), sin(angle)) * radius) + center
\$Sprite2.position = coord
angle = 0
``````

You will have to find a way to have a linear speed and handle the looping

by (81 points)
+1 vote
``````func rotate_around_point(vec: Vector2, center: Vector2, angle:float) -> Vector2:
var diff:Vector2 = vec - center
diff = diff.rotated(angle)
diff += center
return diff
``````
by (899 points)
edited