How to make an object parent to another?


I would like to ask for some help.
I would like to achieve that,if I’m rotating an object,an other object follow the rotation of the rotated object.
In other game development tools,languages this technique what I’m looking for is called “Parenting”, which makes an object a parent of an other object which became a “child” object this way.The aim of this feature is that,the child object always keep it position relating to it parent object.
So,if I positioning the child object on the left side of the parent object,even if the parent object is rotating,the child object is follow it rotation and stay on the left side of the parent object.Also valid for the child object’s direction and distance relating to parent object.
The child always keep it position,direction and distance relating to parent.
This feature also called some places “Pinning”,so we can “pin” an object to an other. Same thing only called different.

In GameDevelop I can’t find this feature and I get stuck :cry:
I have no idea how to make it,because in the past whatever tool I’ve been used it had this feature. :blush:

Anybody could help me please,how to achieve this in GameDevelop?


It is easy if you know ‘who are the objects’, you only need one event and two actions: first action copy to the child object the position of the parent object, and second action copy the direction.
Game Develop has two basic sprite points: ‘Origin’ and ‘Centre’, ‘Origin’ is the real object’s position, and ‘Centre’ is over the sprite is rotated.

In your parent object, you put the ‘Origin’ and ‘Centre’ points where you like. But you have to add a point (i.e. ‘Child1’) and put it where the child object must be.
In your child object, you don’t add any point, but you have to put the ‘Origin’ and ‘Centre’ points in the same place, because if the ‘Centre’ is not in the same position of ‘Origin’ the rotation will be degenerated, not the same of the parent object, here is an image to explain:

Blue point is the ‘Origin’
Red point is the ‘Centre’
Green point is the ‘Child1’
Note that in the child, pink object, the ‘Origin’ and ‘Centre’ are in the same place.

Now you add this event:

Always: ........Do = Parent.PointX(Child1) and = Parent.PointY(Child1) to the position of the object Child ........Do = Parent.Direction() to the direction of Child

1 Like

Thanks a lot . I’m very grateful for your help :slight_smile:

Lizard13, hard to say that, but your implementation of parenting is flawed.

First of all, parenting one object to another isn’t just simple copy position/copy rotation.

It must follow certain rules:

  • If parent moves/rotates, children moves/rotates as well (relative to parent, not copying its position/rotation).
  • If child moves/rotates, parent and rest of parent’s children are unaffected, only child moves.

And yes, I realize it would be hell to implement for every object you want to parent to another. That’s why I’ve made feature request related to this.

I’m sure simply adding a variable to describe if the object is child or parents would do this just fine. Each object could have Variable family = ‘child’ or Variable family = ‘parent’ and then when an object where family = ‘parent’ moves, then all objects ‘child’ copy it. If you wanted to set this up for mass amounts of objects, you can simply the link objects and do this (in this example, just to match the movespeed, but any action could be copied):

Create object Ship
Ship.Variable(family) = ‘parent’

Create object SupportShip
Supportship.Variable(family) = ‘child’
Link SupportShip and Ship

If(Ship.Variable(movespeed) > 0)
take into account all SupportShip linked to Ship
SupportShip.Variable(family) = child |||| Actions: Do = Ship.Variable(movespeed) to variable movespeed of SupportShip.[/code]

I’m currently writing an RTS type game in GD and in the next few days will be embarking on the creation of some parent/child type code for one of the units (a leader). I’ll put it up here when I’m done with it. :wink:

1 Like

I’ve just made an example of how to properly implement a child/parent engine with Game Develop :slight_smile: Check it here:

Of course, it can be extended to share more information between the child and the parent: It’s up to the game designer to do such modification so that the system fulfill his need :slight_smile:

1 Like