Page 1 of 1

Adopting parents animpos

PostPosted: Sat May 19, 2012 10:23 am
by Troodon
Hi,
I have a fighter plane's core that rotates around itself smoothly 360 degrees. Then I have smaller actors installed on it, engines and weapons and such. They have also 360 degrees rotation and the plane's core is their parent. It worked fine in first testings, the plane rotated 360 degrees and the pieces on board rotated around it so that it looked like they were physically sitting on it. I used the code line (in global code):

animpos = fighter_core.animpos;

for the pieces onboard.

The game mechanic anyway needs to support fleets of fighter planes so I changed that part of the code into:

animpos = parent.animpos;

Then I tested in game mode again but this time, the pieces don't move anymore with the plane! When I turn the nose left or right, the pieces just stay in the same position of the animation, making them just float in the air.

Question in short: How can I make the pieces follow their parent actors animpos?

Thank you :)

Re: Adopting parents animpos

PostPosted: Sat May 19, 2012 1:32 pm
by savvy
You have done it right, it owuld be
Code: Select all
animpos=parent.animpos;
Maybe the parent isn't being assigned properly?

EDIT: are the parts being created by the thing its parented to? if so you could/should try using
Code: Select all
animpos=creator.animpos;


savvy

Re: Adopting parents animpos

PostPosted: Sat May 19, 2012 9:04 pm
by Troodon
The parent-relation is assigned when the actors are created. And yes, they are created by the parent actor.

I tried to change parent to creator but the problem persisted.

Re: Adopting parents animpos

PostPosted: Sat May 19, 2012 10:31 pm
by skydereign
If the ship parts are indeed parented to the the actual ship, your code should work. Easy way to tell is move the ship actor, if the parts move they are parented. Since they aren't rotating properly, it sounds like they are parented to the wrong actor (or a non-existent actor).

Re: Adopting parents animpos

PostPosted: Sun May 20, 2012 9:53 am
by Troodon
The parent-relation is assigned in the fighter_core -> create actor -> script editor as:

CreateActor("fighter_engine1", "A_fighter_engine1", "Event Actor", "(none)", 0, 0, false);

for each. Tried also "Creator Actor" instead of "Event Actor" but didn't help.

When I move the ship actor, the parts move with it. They just don't change their animpos to the ship's animpos.

Re: Adopting parents animpos

PostPosted: Sun May 20, 2012 1:01 pm
by savvy
This is strange.
Have you use ChangeAnimationDirection on the turrets? if the animation direction isn't changed to stop then this will cause it to do what is happening here.

savvy

Re: Adopting parents animpos

PostPosted: Sun May 20, 2012 1:59 pm
by Troodon
Yes, their animations are stopped when they are created.

Re: Adopting parents animpos

PostPosted: Sun May 20, 2012 3:23 pm
by Bee-Ant
fighter_core -> Create Actor:
Code: Select all
CreateActor("fighter_engine1", "A_fighter_engine1", "Event Actor", "(none)", 0, 0, false);


fighter_engine1 -> Draw Actor:
Code: Select all
char str[32];
Actor *get;
sprintf(str,"fighter_core.%i",cloneindex);
get=getclone(str);
animpos=get->animpos;

Re: Adopting parents animpos

PostPosted: Sun May 20, 2012 4:22 pm
by Troodon
I wouldn't mind some explanations Bee :P

ChangeParent("fighter_engine1", "Event Actor"); <- Wouldn't this make every fighter_engine1 child of the created fighter_core?

Also, what's happening in that draw actor code?

It creates an char variable array with 32 slots? And then gets every actor? And then inputs the characters of "fighter_core.%i" in the variable? And uses that number to chose the clone? All this to choose who's animpos the engine is using?

Why oh why? And what's wrong with just using animpos = creator.animpos?

Re: Adopting parents animpos

PostPosted: Sun May 20, 2012 4:39 pm
by Bee-Ant
Troodon wrote:ChangeParent("fighter_engine1", "Event Actor"); <- Wouldn't this make every fighter_engine1 child of the created fighter_core?

I did an edit on my previous post.

Troodon wrote:It creates an char variable array with 32 slots? And then gets every actor? And then inputs the characters of "fighter_core.%i" in the variable? And uses that number to chose the clone? All this to choose who's animpos the engine is using?

Troodon wrote:The parent-relation is assigned when the actors are created. And yes, they are created by the parent actor.

fighter_engine is created when fighter_core is created right?
Since they're clones, that means:
- fighter_core.0 will create fighter_engine.0
- fighter_core.1 will create fighter_engine.1
- etc
Why I use char str[32]? to get the parent name in name.cloneindex format (do I have to explain what cloneindex is?).
And it's not "gets every actor", but "gets assigned actor only".
The outcome of sprintf(str, "fighter_core.%i", cloneindex); is decided by the each fighter_engine cloneindex. fighter_engine with 9 cloneindex will get "fighter_core.9" output, fighter_engine with 4 cloneindex will get "fighter_core.4" output.
And we use getclone(str); to create a link to the clone (in this case the parent) that's it's name is stored within str.
And then assign parent's attribute to the child with animpos=get->animpos;

Actually using a mere animpos=parent.animpos; in DrawActor will get the job done. But since it doesn't work (in your case), so I provide another way to solve that.
One thing to note, avoid assigning local variables in Global code.

Re: Adopting parents animpos

PostPosted: Sun May 20, 2012 6:04 pm
by Troodon
:roll:

I'll give it a try later but I still feel weird about it not working in the simple way. Could it be a bug that would get fixed if I just rebuild the ged file from the beginning?

I remember there was some bug related to the parent-child thing but can't recall it..maybe about the z level?

Re: Adopting parents animpos

PostPosted: Sun May 20, 2012 7:31 pm
by skydereign
Troodon wrote:I remember there was some bug related to the parent-child thing but can't recall it..maybe about the z level?

What I think you are talking about isn't a bug, that is a feature. I can get the code to work properly with just what we discussed here. So I don't think it is a bug, but rather something in your setup that is messing with hit. Can you replicate it not working in a small ged (with just the ship and attachments)?