How can I rotate an object in Gdevelop relative to a specific point on the object?

I have a robot object in my game:


I want the robot to rotate around this point when I press the A key:

And when I press the D key, the robot should rotate relative to this point:

I realized that the object rotates relative to the center point. But I can only move the center point in the point editor. Is it possible to do this using events? Maybe there is an extension or a JavaScript method that allows me to change the center point.Or is there another way to implement my idea?

Hi - You can have different center points in different animations of the same object - i just checked. Keep the origin in the center and change ani when you want it to rotate the other way


1 Like

Thank you! Now we need to make that the object doesn’t change its position when the center point changes…

Have you kept the origin the same?

Yes, I placed the original point in the center, just like you did. If you don’t rotate the object, the object stays in the same place when you change the animation, but if you rotate it, the object changes its location when you change the animation.

It’d be simpler to have a second object (say called rotator), with origin at its centre, place that at the point you want to rotate the robot.

Then use the sticker extension, stick your robot to the rotator object and rotate the rotator object. The robot will spin as you want it to.

1 Like

I have solved the problem. To do this, I created an additional point called “Center2”.


In the first animation, it shows where the center point will be if we change the animation. And in the second animation, the opposite is true:

Then I created such variables for the object:

And then he wrote such events. These events need to be improved and optimized, of course, but now we know which direction to take.

2 Likes

Thank you! I will try

I like your solution! - I think you might be able to refer to the custom points directly in the change centre event rather than use a variable. Thinking back now - I had a similar problem when i had a collection of hinged stones - I can’t remember the solution that i used though! - all the best with it!

1 Like

Exactly, it will be easier and clearer without using variables. Thanks!