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

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

    - Thomas
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @Socks -- Very, very nice. Great Idea!
  • DenimSharkDenimShark 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.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Just wow.

    Thanks!!!
  • mataruamatarua 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 :)
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    @Socks very neat; I really like the slider graphics too. :-)
  • -Timo--Timo- Member Posts: 2,313
    edited December 2013
    very nice, thanks for sharing! :D
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Nice as I suck at trig!
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Top stuff
  • JSprojectJSproject Member Posts: 730
    Great one @Socks :)
  • SocksSocks London, UK.Member Posts: 12,822
    @everyone !

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

    Cheers ! :)>-
  • kinzuakinzua Member Posts: 554
    thanks for sharing @socks
  • vuifahvuifah Member Posts: 62
    Great stuff. Thank you for sharing.
  • allc1865allc1865 Member, PRO Posts: 777
    Way too cool! Thanks for sharing! :) ;)
  • artfishartfish Member, PRO Posts: 369
    Awesome.
  • LumpAppsLumpApps Member Posts: 2,881
    Solid! Well done!
  • UtopianGamesUtopianGames Member Posts: 5,692
    Me likes :)

    Darren.
  • 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..
  • SocksSocks 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 add three constrain behaviours to your 'child' actor.

    Then copy the values from LinkMachine™ to the three constrain behaviours in your 'child' actor.
  • neomanneoman Member, BASIC Posts: 826
    edited January 2014
    Thanks for that @Socks I love your work ... This might be useful in the future ... Cheers ;-)
  • SocksSocks 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 :)>-
  • ArmellineArmelline Member, PRO Posts: 5,415
    Love it! Can't believe I didn't see it when it was first posted! Will definitely be using it some time!
  • PBEmpirePBEmpire Member Posts: 676
    Video no longer available!
  • SocksSocks London, UK.Member Posts: 12,822
    edited January 2014
    Video no longer available!
    I'll repost the video a little later.
  • SocksSocks 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 !
  • SocksSocks London, UK.Member Posts: 12,822
    edited February 2014


    @PBEmpire . . "Video no longer available!"

    New video . . .

  • gtgartgtgart 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.

Sign In or Register to comment.