Get the relative coordinates of a child when using the new hierarchy feature

0 favourites
  • 4 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • Hi!

    My object is a child of another object. I want my object to move to a location and then return back to it's original location. I think I would need to store it's original location in order to do that. But it seems that the original location is relative to it's parent object. So the question is: how can I get the relative coordinates of a child object?

    Tagged:

  • If you have chosen to have the child object transform with the x and y positions of the parent then this will interfere with any independent movement of the child object.

    If not, you can use instance variables to store the X and Y coordinates of the object and then use them to navigate back to.

    For example.

    On left click

    - Set object var_x to self.x

    - Set object var_y to self.y

    - set position to mouse.x, mouse.y

    On right click

    - set position to self.var_x, self.var_y

    If you want it to transform with the parent object and the parent object is also moving, you can still use variables to store the position but you would use distance and angle to the parent instead of self.x self.y.

    For example.

    On left click

    - set object var_distance to [distance(parent.x,parent.y,self.x,self.y)]

    - set object var_angle to [angle(parent.x,parent.y,self.x,self.y)]

    - move to mouse.x, mouse.y

    On right click

    - Set position to

    X: [parent.X+cos(self.var_angle)*self.var_distance] Y:[parent.Y+sin(self.var_angle)*self.var_distance]

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi!

    Thank you for a detailed response! Finally had the chance to test this today. I think your second method is suitable for me, but unfortunately the result still seems to be off. Here are the relevant events as text:

    [images]

    ----+ Touch: On touched images

    --------+ images: Pick Own parent feebackBGTiled

    ---------> images: Set angleToParent to angle(feebackBGTiled.X,feebackBGTiled.Y,Self.X,Self.Y)

    ---------> images: Set distanceToParent to distance(feebackBGTiled.X,feebackBGTiled.Y,Self.X,Self.Y)

    ------------+ images: [X] Is scaled

    -------------> images: Tween "" property Position to ScrollX, ScrollY in 0.5 seconds (In Out Sinusoidal, destroy: No, loop: No, ping pong: No)

    -------------> images: Tween "" property Size to images.Width×2, images.Height×2 in 0.5 seconds (In Out Sinusoidal, destroy: No, loop: No, ping pong: No)

    -------------> images: Set scaled to True

    ------------+ System: Else

    -------------> images: Tween "" property Size to images.Width÷2, images.Height÷2 in 0.5 seconds (Default, destroy: No, loop: No, ping pong: No)

    -------------> System: Wait 0.5 seconds

    -------------> [DISABLED] images: Tween "" property Position to images.origX, images.origY in 0.5 seconds (Default, destroy: No, loop: No, ping pong: No)

    -------------> images: Tween "" property Position to (feebackBGTiled.X+cos(Self.angleToParent)×Self.distanceToParent), (feebackBGTiled.Y+sin(Self.angleToParent)×Self.distanceToParent) in 0.5 seconds (Default, destroy: No, loop: No, ping pong: No)

    -------------> images: Set scaled to False

    A screenshot might look more clear:

  • I noticed the problem now: I'm resetting the values on every touch by mistake. The isScaled boolean should obviously be checked right where the original values are stored.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)