London, UK.Member Posts: 12,822
edited February 2014

A question comes up from time to time on the forums . . . . "how to attach one actor to another actor so they stay together" . . . . the obvious answer is to constrain the X and Y of one actor to the X and Y of the other actor.

This works for most situations - like a police siren/light actor on the roof of a police car actor - but if the 'parent' actor (the police car) is doing anything like spinning, turning or bouncing around the scene then simply constraining the X & Y of the child actor to the parent actor doesn't work as the child will not rotate with the parent actor.

If you also constrain the rotation of the child actor to the rotation of the parent actor then it still won't work as when the parent actor rotates the child actor will stay where it is in relation to the parent actor and just rotate around its own centre point - for example with our hypothetical police car actor + siren/light actor set-up, if the police car were to rotate (imagine it driving around a 'loop-the-loop' on a roller-coaster) then the siren/light actor would always stay directly above the police car actor, even when the police car actor is completely upside down.

So just constraining the X & Y & rotation of the child actor to the parent actor doesn't do the trick.

What you have to do is to throw a bunch of trigonometry at the child actor to get it to stick to the parent actor as if the two are one piece, even when the parent actor is falling and spinning and hitting stuff and generally being thrown around.
The trigonometry is not too complex, but it's also not particularly intuitive. I've been doing a lot of this kind of thing on one particualr project I'm working on so I ended up making a little machine to generate the code for me as it was easier than working out the trigonometry each time.

. . . . . . . . . . . . . . . . . . . . . . . . .

This is how it works:

1) In the project you have a parent object and a child object.
2) You use three sliders to position the child actor in relation to the parent actor.
3) When the child actor is in position you press the 'code' button which generates your code (three constrains behaviours).
4) You go back to your own project and place your own child actor in your scene and unlock it (so it can see the parent actor's values)
5) Then add three constrain behaviours to your 'child' actor and enter the values generated by the LinkMachine™ .

The three sliders are Orbit (blue) Radius (red) and Rotation (yellow).

Orbit controls the angle the child 'orbits' the parent object at.
Radius controls the distance of the child from the centre of the parent.
Rotation controls the rotation of the child actor (around its own centre point).

Using these three controls you can place the child anywhere, and at any angle, in relation to the parent.

. . . . . . . . . . . . . . . . . . . . . . . . .

Other stuff.

Clicking on the white triangle above the three sliders resets them all to their default values.
Option + clicking on any individual slider control resets just that slider to its default value.
Clicking on the red triangle on the parent actor resets it to its default position.

Hit the code button to show the three constrains behaviours the positioning of the child actor has generated.

If you want to see the linking/parenting in action then you can grab the parent actor and throw it around, switch on the test button to bring up four collision points that will throw the parent actor off balance when it hits them so you can see the linking/parenting as the two actors spin and tumble around the scene together.

You can replace the default child and parent actors with your own actors, simply drag your own artwork onto them and then resize them to their correct sizes.
«1

• Member, Sous Chef, PRO, Bowlboy Sidekick Posts: 9,061
Very nice, @Socks! Thanks for sharing with the community!
• Member Posts: 1,603
Epic one buddy - keep it up! I'll be using it.

- Thomas
• Member, Sous Chef, PRO Posts: 2,866
@Socks -- Very, very nice. Great Idea!
• Member Posts: 192
I'd create a cartesian coordinate version of it too. It would be a simple alteration, in case the user wants it to be constraint using x and y offsets instead of spherical coordinates. Nice job.
• Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,947
Just wow.

Thanks!!!

New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

• Auckland, New ZealandMember Posts: 854
You are shiz @Socks - nice work once again - it's looking really solid too - sometimes in times gone by things that need to stick together drifted apart. Seeing stuff like this is awesome
• I am here.Member, Sous Chef, PRO Posts: 6,598

@Socks very neat; I really like the slider graphics too. :-)

""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

• Member Posts: 2,313
edited December 2013
very nice, thanks for sharing!

# ✮ Available for hire! support@gsinvention.com ✮

• Member Posts: 9,914
Nice as I suck at trig!
• Member Posts: 5,390
• Member Posts: 730
Great one @Socks
• London, UK.Member Posts: 12,822
@everyone !

Cheers >- Hope it's useful.
• Member, Sous Chef, Senior Sous-Chef Posts: 9,934
wow thats pretty stinking cool. Good job
• London, UK.Member Posts: 12,822
@tenrdrmer

Cheers ! >-
• Member Posts: 554
thanks for sharing @socks
• Member, PRO Posts: 62
Great stuff. Thank you for sharing.
• Member, PRO Posts: 777
Way too cool! Thanks for sharing!
• Member, PRO Posts: 369
Awesome.
• Member Posts: 2,878
Solid! Well done!
• Member Posts: 5,690
Me likes

Darren.
• Member Posts: 278
Hi, can we import the code on another project.. Please can some one help as I click on generate but do not i do not see full code on screen and do not know what to do with the code.. can some please send a video tutorial, on how does this work plzzzzzzzzz..
• London, UK.Member Posts: 12,822
Hi, can we import the code on another project . . . . .
@nabbo

Press the 'code' button to generate the code.

Go back to your own project and place your own 'child' actor in your scene and unlock it.

Then copy the values from LinkMachine™ to the three constrain behaviours in your 'child' actor.
• Member Posts: 817
edited January 2014
Thanks for that @Socks I love your work ... This might be useful in the future ... Cheers ;-)
• London, UK.Member Posts: 12,822
edited January 2014
Thanks for that @Socks I love your work ... This might be useful in the future ... Cheers ;-)
Cheers @neoman >-
• Member, PRO Posts: 4,981
Love it! Can't believe I didn't see it when it was first posted! Will definitely be using it some time!
• Member Posts: 676
Video no longer available!
• London, UK.Member Posts: 12,822
edited January 2014
Video no longer available!
I'll repost the video a little later.
• London, UK.Member Posts: 12,822
Love it! Can't believe I didn't see it when it was first posted! Will definitely be using it some time!
Cheers big ears !
• London, UK.Member Posts: 12,822
edited February 2014

@PBEmpire . . "Video no longer available!"

New video . . .

• Member Posts: 5

Can someone explain the expression syntax? Do I type into the expression box, i.e..
52 *cos((Target.Rotation)+90)+Target.PositionX
where Target is my parent actor.