0 votes

I have a point1 (Vector2), I want this point to rotate around another point2 (Vector2) (On the same node without adding new nodes).
The rotated () function works but rotates point1 around the origin of the scene. How do I make the center of rotation of point1 be point2?
I try to do it with Transform 2D but I know how, and when I try to multiply Vector2 with Transform 2D it can't. To visualize it I simply draw a small circle at the position of point 1 in _draw() function.

asked May 24 in Engine by estebanmolca (1,199 points)

2 Answers

0 votes
Best answer

The rotated () function works but rotates point1 around the origin of the scene. How do I make the center of rotation of point1 be point2?

You just need to add point2 to the result. ;) Also take a look at this answer.

answered May 24 by njamster (8,986 points)
selected May 24 by estebanmolca

Thanks, what is easy sometimes becomes difficult...My function to move the point and rotate it:

 func rotated_point(_center, _angle, _distance):
        return _center + Vector2(sin(_angle),cos(_angle)) * _distance
0 votes

Maybe this will help

var diff = point1 - point2
var rotated_vector = diff.rotated(angle) + point2
answered May 24 by supper_raptor (667 points)

Thanks for the answer, the previous method worked for me but this is another way of doing the same ...

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.