I’m trying to make a parent-child system in GDevApp, in GDevelop I can use points to make such thing, but in GDevApp I can’t add custom points to objects at the moment so I’m trying to use math to calculate child position compared to parent object. But I have problem with the calculation when the parent object start rotating. The child object should follow the movement and rotation of parent object. I can solve movement (left, right, up, down) on X and Y axis, but I have trouble with the rotation because when the parent start rotating, I’m not sure how to calculate the new position of child object on X and Y compared to rotation (Direction, Angle) of the parent.
So in your case, X;Y would be the position of the child relative to the parent, NewX and NewY will be the position of the child relative to the parent, and Angle is the angle of the parent. If you want to position the child:
I’m getting closer, but it still not perfect, maybe I don’t get it how should I use this formula
The child object orbit around the parent object too fast like planets around the sun which is cool, but it not something I want. If the child object is on the right side of the parent, it should stay there wherever the parent is rotating and move, the child always should stay on the right side of the parent.
But instead it orbit around the parent
First, cos and sin are using radians and Angle() returns degrees, so you have to add ToRad to each parameter of cos or sin: cos(Something.Angle()) should be cos(ToRad(Something.Angle()))
Second, in fact, I just realized that there is already a function that do all the calculations for you. It’s “Put an object around a position” (or around an object). It’s an action specifically designed for this purpose, so better use it
You just have to enter the angle, the position of the object, the distance and here you go!
The problem with the “Put an object around a position” is that, for distance I would like to keep the actual distance of child object from the parent, I don’t want to set distance manually. So I can just put a turret on the wings of my plane in the editor and it stay there relative to the plane. If I use Distance() expression, it just doesn’t work for some reason, it returns lower value than the real distance.
Anyway, using this formula the parent-child system almost worked a minute ago, but there was a little bit of excursion in the position of the child when the parent was rotating to the left, I was thinking it because it using the origin point or something so I tried to use PointX(Center) and PointY(Center) instead X and Y, but made it worse, now even with X and Y doesn’t work But I don’t remember I have changed anything other than X and Y to PointX and PointY
Maybe I overlook something, don’t know I guess I’m going to wait for points to be released in GDevApp