Constraining Actor to another and staying there

TouchTiltGamesTouchTiltGames Member Posts: 1,162
edited November -1 in Working with GS (Mac)
I've got an 'arm' that can move up and down that is contrained to a box and when I move the box around the screen, the arm moves with the box of course but isn't constrained where the arm meets the box...Seems like it's constrained at the middle registration point of the arm? I'm just guessing.

How would I constrain the arm to the box where the arm meets the box?

On the arm:

self.position.X to: game.armX -300
self.position.Y to: game.armT -5

On the box:
game.armX to: self.position.Y
game.armY to: self.position.X

Thanks for any help!

Comments

  • old_kipperold_kipper Member Posts: 1,420
    that seems correct. I would adjust the offset numbers in the arm until its in the correct position. To move it up and down I would add a variable with the offset such as selfposition.y to (game.armY-5)+(some number attribute you can alter to give movement).

    hope that helps. kipper
  • TouchTiltGamesTouchTiltGames Member Posts: 1,162
    Thanks, Kipper.

    Yeah I actually do have it in the position I want it..it's just weird - when the box goes over a hill let's say, the arm doesn't rotate up with the box when it's going up the hill and it doesnt rotate down when the box is going down the hill. Not sure if I'm missing something in my contraining...

    And by "rotate" i mean..doesnt really move with the box if the arm was extended out. So I'm guessing i need to constrain the rotation too..but not sure how to do that.
  • TouchTiltGamesTouchTiltGames Member Posts: 1,162
    NM I got this for constraining rotation too:

    in the truck actor

    constrain attribute truck rotation (angle) to self rotation

    in the trailer actor

    constrain attribute self rotation to truck rotation
  • TouchTiltGamesTouchTiltGames Member Posts: 1,162
    Ok I'm still having trouble with this. I've got the position and rotation of the arm constrained to the side of a box and that 'works', but when the box goes up a hill (rotates), the arm still moves up the side of the box and if the box goes down a hill, the arm moves down. I want the arm to stick the rotation and position right where it is on the side of the box...

    Anyone?
  • iAppleDeviAppleDev Member Posts: 13
    just wait for the joint rule! then you can do that.
  • TouchTiltGamesTouchTiltGames Member Posts: 1,162
    Ha yeah that would be awesome..looking forward.

    But there must be a way with Math that I can tell the arm to stay in one spot while the box is rotating and moving around....?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    You are trying to get the 'arm' to stick to the box? And the arm needs to keep its same angle (relative to the box) as the box moves and rotates?

    There are probably several ways to do this, here is what I would suggest. It creates a 'joint'.

    Change the names of the game level attributes armX and armY. Change them to boxX and boxY. (This will give a clear picture of what is being tracked.) Also create a real game level attribute called boxRotation.

    Then in the box actor, the behaviors would be:
    Change Attribute: game.boxX To: self.Position.X
    Change Attribute: game.boxY To: self.Position.Y
    Change Attribute: game.boxRotation To: self.Rotation

    Then in the arm actor create three 'real' attributes: beginningRotation, beginningDistanceFromBox, beginningAngleFromBox. (I like nice long descriptive names. You can call them what you want, but it will help to get the concept if they are long descriptive names.)

    Still in the arm actor add the following six behaviors:
    Change Attribute: self.beginningRotation To:self.Rotation
    Change Attribute: self.beginningDistanceFromBox To: magnitude( game.boxX - self.Position.X , game.boxY - self.Position.Y )
    Change Attribute: self.beginningAngleFromBox To: vectorToAngle( self.Position.X - game.bossX , self.Position.Y - game.boxY )
    Constrain Attribute: self.Rotation To:game.boxRotation + self.beginningRotation
    Constrain Attribute: self.Position.X To: game.boxX +( self.beginningDistanceFromBox *cos( game.boxRotation + self.beginningAngleFromBox ))
    Constrain Attribute: self.Position.Y To: game.boxY +( self.beginningDistanceFromBox *sin( game.boxRotation + self.beginningAngleFromBox ))

    When you are finished, you can place the arm where you want on the scene and it will keep the same distance and rotation in relation to the box, no matter where you move and rotate the box. It is a 'revolute' joint.

    Hope this helps!
  • SnapFireSnapFire Member Posts: 361
    Or...... you could just wait for Joints LOL.

    That's a lot of trouble, but if it works, go ahead.

    Good Luck
    -Thomas
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @SnapFire -- It is a little bit of work. But I've been waiting for joints long enough! And it does work.

    Try it! You might like it!
  • SnapFireSnapFire Member Posts: 361
    I remember a long time ago on my second attempt at a project I needed something just like this. Frustrated me for days! It was probably good I didn't figure it out as it really was a terrible idea. And I came up with a new idea from the experience. I suppose some things are meant to be.

    If the need ever arises, I'll definitely use this. Looks legit anyway ;)

    -Thomas
  • iAppleDeviAppleDev Member Posts: 13
    RThurman said:
    You are trying to get the 'arm' to stick to the box? And the arm needs to keep its same angle (relative to the box) as the box moves and rotates?

    There are probably several ways to do this, here is what I would suggest. It creates a 'joint'.

    Change the names of the game level attributes armX and armY. Change them to boxX and boxY. (This will give a clear picture of what is being tracked.) Also create a real game level attribute called boxRotation.

    Then in the box actor, the behaviors would be:
    Change Attribute: game.boxX To: self.Position.X
    Change Attribute: game.boxY To: self.Position.Y
    Change Attribute: game.boxRotation To: self.Rotation

    Then in the arm actor create three 'real' attributes: beginningRotation, beginningDistanceFromBox, beginningAngleFromBox. (I like nice long descriptive names. You can call them what you want, but it will help to get the concept if they are long descriptive names.)

    Still in the arm actor add the following six behaviors:
    Change Attribute: self.beginningRotation To:self.Rotation
    Change Attribute: self.beginningDistanceFromBox To: magnitude( game.boxX - self.Position.X , game.boxY - self.Position.Y )
    Change Attribute: self.beginningAngleFromBox To: vectorToAngle( self.Position.X - game.bossX , self.Position.Y - game.boxY )
    Constrain Attribute: self.Rotation To:game.boxRotation + self.beginningRotation
    Constrain Attribute: self.Position.X To: game.boxX +( self.beginningDistanceFromBox *cos( game.boxRotation + self.beginningAngleFromBox ))
    Constrain Attribute: self.Position.Y To: game.boxY +( self.beginningDistanceFromBox *sin( game.boxRotation + self.beginningAngleFromBox ))

    When you are finished, you can place the arm where you want on the scene and it will keep the same distance and rotation in relation to the box, no matter where you move and rotate the box. It is a 'revolute' joint.

    Hope this helps!

    Yes, But then it won't have collisions with any actors? GoodLuck with the physics, for doing things like the shocks/suspension or the wheels rotating/spinning with a physical connection and friction for moving the truck(GAS) or the tires to spin/roll forward, back and stop true to the physical motion was also hard and it took me a while to figure out without using any animations.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    iAppleDev said:
    Yes, But then it won't have collisions with any actors? GoodLuck with the physics, for doing things like the shocks/suspension or the wheels rotating/spinning with a physical connection and friction for moving the truck(GAS) or the tires to spin/roll forward, back and stop true to the physical motion was also hard and it took me a while to figure out without using any animations.

    Physics work OK. Actors collide with it just fine. But as with any actor that has its physics overridden by constrain behaviors -- it might take a little thinking to make it work the way you want it to.

    Try it! You might like it!
  • TouchTiltGamesTouchTiltGames Member Posts: 1,162
    Thanks RT...yeah the arm rotates up and down on an animation so I'm faking the joints.

    Yes the arm needs to stay where it is at the base, sticking to the box as the box rotates/moves around. I'll give this a try today/tomorrow. Thanks A LOT for this really appreciate.

    And yeah I've come so far with this already I'll try your option before I just wait for mmm delicious joints. lol.

    cheers.
  • TouchTiltGamesTouchTiltGames Member Posts: 1,162
    RT thank you! This worked beautifully. Cheers :)
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    TouchTiltGames said:
    RT thank you! This worked beautifully. Cheers :)

    You are welcome. GameSalad is pretty powerful!

    The only "gotcha" to worry about is that this setup needs to have the box always start with its rotation at 0 degrees. (It would take a little more math to get it to start at any angle.)

    RThurman
  • TouchTiltGamesTouchTiltGames Member Posts: 1,162
    Hmm yeah ok, thats funny because the 'arm' that I have attached the box, I'm trying to restrict the rotation 20 degrees to the left and 20 to the right. Not restrict but if it goes past that, then something happens. Hasn't been working too well so that maybe why...
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    TouchTiltGames said:
    Hmm yeah ok, thats funny because the 'arm' that I have attached the box, I'm trying to restrict the rotation 20 degrees to the left and 20 to the right. Not restrict but if it goes past that, then something happens. Hasn't been working too well so that maybe why...

    I don't think that its an issue with this setup. The 'arm' should be able to rotate freely. Any 'extra' rotation should get added on to the constrain attribute like this:

    Constrain Attribute: self.Rotation To: game.boxRotation + self.beginningRotation + (any additional rotations)

    It all additive!

    Perhaps your test for +- 20 degrees isn't working properly. Are you testing for 'greater than' or 'less than' rather than 'equals'? Many a "coder" gets tripped up by using 'equals' when they want to be using 'greater than'.

    Hope this helps!
    RThurman
Sign In or Register to comment.