playMaker

Author Topic: SetParent movement question - moving object's position changes  (Read 115 times)

szomaza

  • Full Member
  • ***
  • Posts: 194
    • View Profile
SetParent movement question - moving object's position changes
« on: October 24, 2018, 09:55:49 AM »
I have used the SetParent action a lot but have a problem now that I can't explain.
The SetTransformParent behaves exactly the same, so I guess it is not a bug, but I don't know how to solve it or the reason this is happening.

I have an empty test object that I parent back and forth (with 1 sec delays) between a few empty test objects, around and around, one after the other, which are in different positions.

ResetLocalPosition and Rotation is FALSE in the SetParent actions, and first everything works as expected: the object stays in place just moves in the Hierarchy to the other parents, one after the other.
Problem starts, when I grab the Object being parented and move it around while it is being parented: it starts jumping around as it goes from one parent to the other.
It does move nicely along with the cursor all the time, but jumps to another spot when it gets parented to a new parent.
While it is parented to the original parent it jumps to the cursor and keeps on nicely moving with it.

My problem is that I was not expecting this jumping of the moving object when it is parented to another parent.
Why is this?
How can I get a moving object to keep moving on steadily, while it's parent is updated.

Thanks for any enlightenment,
szomaza

Thore

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: SetParent movement question - moving object's position changes
« Reply #1 on: October 24, 2018, 11:43:42 AM »
Sounds like that it is being calculated to local space of the previous parent, and when you move it around, it is still is considered part of another local space, and this causes the wonky behaviour. Just a guess.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3602
    • View Profile
    • jinxtergames
Re: SetParent movement question - moving object's position changes
« Reply #2 on: October 24, 2018, 01:20:16 PM »
Hi.
I know that parenting while mouse look also does give strange behavior.

What exactly are you to trying to achieve, maybe it is possible by using get/set position 'following' the parent instead.

szomaza

  • Full Member
  • ***
  • Posts: 194
    • View Profile
Re: SetParent movement question - moving object's position changes
« Reply #3 on: October 27, 2018, 12:36:22 AM »
Yes, I could get the world position of the object, parent it, and then set the world position back but wouldn't that cause it to flicker for a moment, as the parenting moves it away, and then the set world position moves it back?

Or do I read it here correctly that every action in a state is run in the same frame?
So there won't be no flickering?
https://hutonggames.fogbugz.com/default.asp?W174

What I am trying to do is random generating the level for a platformer:
- place a platform,
- spawn some elements: enemies, helpers, coins, etc. onto some child points (I use SetParent with ResetLocalPosition TRUE) of the platform,
- then when the platform is out of the camera view, parent it back to the platform pool object to be reused later,
- BUT some elements of the platform which were spawned to be parents of the platform's spawn point, have to stay around for longer, so this is when I tried to parent the element, to a temporary parent (to remove it from the platform before moving that away) and was hoping it would stay in the same position, but instead it jumps to another location.
(Thore is probably right with the local space guess.)

I'll try and return with the result.....

edit: it works nicely, the object does not flicker at all:
- GetPosition in World space,
- Parent away from the platform to something else,
- SetPosition back to same World space position.
all in the same state.

- Move the platform away, (this is actually in another FSM)

Thanks,
szomaza
« Last Edit: October 27, 2018, 01:44:10 AM by szomaza »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3602
    • View Profile
    • jinxtergames
Re: SetParent movement question - moving object's position changes
« Reply #4 on: October 27, 2018, 03:31:39 AM »
Hi.

Just a note, set position is best done in late update, especially when using every frame :)