Constraining Actor to another and staying there
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!
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
hope that helps. 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.
in the truck actor
constrain attribute truck rotation (angle) to self rotation
in the trailer actor
constrain attribute self rotation to truck rotation
Anyone?
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....?
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!
That's a lot of trouble, but if it works, go ahead.
Good Luck
-Thomas
Try it! You might like it!
If the need ever arises, I'll definitely use this. Looks legit anyway
-Thomas
Try it! You might like it!
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.
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
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