LinkMachine™

SocksSocks London, UK.Member Posts: 12,822
edited February 2014 in Working with GS (Mac)
LinkMachine™

A linking utility for GameSalad users.



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

Comments

Sign In or Register to comment.