Move 2 actors and keep distance
Hi everybody,
i try to figure out, how to move two actors, constraining one to the other. So if i touch and move the Leader, the follower, follows the movement, then, when i touch the FOLLOWER i want to move it separately. As you might guessed, the problem
is to keep their distance witch changes during the positioning. I am really confused on this, i've seen a Tshirbooth's tuttorial for constraining 4 balls to a box, but he used specific distances.
Any help please?
i try to figure out, how to move two actors, constraining one to the other. So if i touch and move the Leader, the follower, follows the movement, then, when i touch the FOLLOWER i want to move it separately. As you might guessed, the problem
is to keep their distance witch changes during the positioning. I am really confused on this, i've seen a Tshirbooth's tuttorial for constraining 4 balls to a box, but he used specific distances.
Any help please?
Comments
Hi @glynius
That sounds straightforward enough: make a boolean called Follow.
In your leader actor, in the When touch is pressed Rule add Change Attribute Follow to true
Now add in your follow actor, put in the When touch is pressed Rule, Change Attribute Follow to false. THen put the Constrain Behaviour in a rule: When Attribute Follow is true. Should work out....
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
I only guessed you'd put the constrain in the follower, you could have just as well put it in the leader actor....
But either way, you'll need an offset.... no worries there, you haven't done anything wrong, you've just got to add the offset...
So assuming your leader actor is moving just on the x axis, in the follower actor's constrain behaviour:
(For this example, I'll suggest a gap between the leader and follower of 40 pixels, so just substitute the actual distance below):
Constrain self.Position.X-40 to scene.Background.LeaderActor.Position.X
and if there's a difference in the vertical, add another constrain Behaviour:
Constrain self.Position.Y-?? to scene.Background.LeaderActor.Position.Y
-------------
Edit: I've just thought: if you can move the follower actor independently as you said, then its distance from the leader will change, so...
Two more (real) attributes, FollowX and FollowY
Put their starting values as the start x and y positions of your follower actor.
In your follower actor, add:
When touch is released
Change Attribute FollowX to self.Position.X
Change Attribute FollowY to self.Position.Y
Now instead of the above (the rules I suggested above this Edit) put:
Constrain self.Position.X-(scene.Background.LeaderActor.Position.X-FollowX) to scene.Background.LeaderActor.Position.X
Constrain self.Position.Y-(scene.Background.LeaderActor.Position.Y-FollowY) to scene.Background.LeaderActor.Position.Y
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps