Constrain one Actor to the position of another?

ozboybrianozboybrian PRO Posts: 2,102
edited November -1 in Working with GS (Mac)
I need to constrain arms and a gun to one actor.

I also need to set it up so that it rotates accordingly with the directional aim button.
Any help?
.
.
.
-----------------------------------------------------
Join the GameSalad Community and have your game noticed for free.
http://www.facebook.com/ListYourTopiPhoneGame
List your Top iPhone Game on FaceBook!

Comments

  • DrGlickertDrGlickert Member Posts: 1,135
    1)
    http://www.youtube.com/user/GameSaladCookbook#p/u/40/JnlxvMlPG-k

    Video Title: Constraining one Actor to a specific point on another Actor in iOS games made with GameSalad.

    Goes through how to constrain 'wheels' on an actor. Can easily be made into arms/legs/guns, etc...

    2)
    Rotation will be slightly more tricky, I'd get the first part taken care of, then play with the rotation settings so that it lines up correctly.
  • m456arcusm456arcus Member Posts: 189
    If it's all the same, then I need something similar: constrain a turret at the proper point on a tank hull, and have it move correctly with the hull.
    Edit: Didn't see your post till I finished posting.
  • DrGlickertDrGlickert Member Posts: 1,135
    This will do that for ya M456arcus. However, be careful of doing it too many times in a scene and/or on too many actors as it can wear on the processor and effect frame rate negatively.
  • m456arcusm456arcus Member Posts: 189
    Good point... However, I was thinking of making some enemies stationary, and tank destroyers don't have turrets. I think I'll be fine for now.
  • ozboybrianozboybrian PRO Posts: 2,102
    The video seems like it's constraining to the mouse position...
  • DrGlickertDrGlickert Member Posts: 1,135
    Basically this is how you do it. It takes math an planning to accomplish this;

    Say you have a player that's body is 50x50, You have a constrain attribute on the body actor of PlayerBodyX and PlayerBodyY. This will be in the middle of the body.

    Let's do some arms, legs, and a head:
    Head Actor; Let's say your head is 10x10. You'll have 2 constrain attributes on the head actor;
    constrain attribute self.position.X to game.PlayerBodyX
    constrain attribute self.position.Y to game.PlayerBodyY + 30

    Where did I get that 30 from??? If you take the middle of the player body and add 25 to get to the top, then add another 5 for the middle of the player's head you'll get 30. This will place the "Head" actor on top of the body actor.

    Now, as you'll notice, we have a LOT of constrain attributes already. We know that Constrain Attribute eats a lot of processor juice so try not to use too many of them.

    This should get you started.

    Good luck!
  • m456arcusm456arcus Member Posts: 189
    Thats what I have now, but the tricky part is when the hull rotates, since its a top down game. It will probably require sin and cosin, but from there I don't have a clue.
Sign In or Register to comment.