Actors get "stuck" when on top of each other
Terrell
Member Posts: 7
I'm trying to make a board game, and am finding that when one actor is on top of another, they get "stuck" together (one is under the other, and all subsequent moves, they move together).
I tried a Collide rule, so they wouldn't get over or under each other, but then if I move a piece onto the board, the piece I'm moving throws all the pieces already on the board all over the place.
Suggestions?
I tried a Collide rule, so they wouldn't get over or under each other, but then if I move a piece onto the board, the piece I'm moving throws all the pieces already on the board all over the place.
Suggestions?
Comments
in the pressed action both actors are responding... in the inside action only when touch is within the borders of the actor does that actor respond.
a Z axis would allow better control.
MH
Changing it to "touch is inside" makes it even worse. As one piece moves over another it "picks up" the second piece, and they are "stuck" together.
Is there a way to only select the top piece?
Another way I thought about would be to turn on "Collide" - then the two pieces that are "stuck" together would move away from each other. But then I'd want to turn "Collide" off again, so a piece could be moved across the board without disturbing other pieces already there.
Is there a way to turn off "Collide" once it's been turned on?
And then your rule with your "touch inside", add another requirement with the Touchable Attribute must be true
think you are going to have to create a gameAttribute ... boolean and name it something like busy
then on game piece...
[Rule] when (All)
touch inside
game.busy = false
...ChangeAttribute game.busy = true
...then nested [Rule] game.busy = true
......then the drag/do stuff
...then nested [Rule] touch is released ChangeAttribute game.busy = false
If you get it to work once... then you can drag the rule to myBehaviors and just apply to the other pieces from there.
MH
EDIT: what FatalCrest said!
I just started a few days ago with GS, so I'm really new at this.
I'm not sure I followed your instructions completely, because it doesn't work.
I made an Attribute (boolean) called DragDrop
And move pieces with a Behavior I call "Move" that looks like this with two rules:
Rule: When (All)
touch pressed
...Change Attribute self.DragDrop = true
...Otherwise Change Attribute self.DragDrop = false
Rule: When All
Attribute self.DragDrop = true
...Constrain Attribute self.Position.X = game.Mouse.Position.X
...Constrain Attibute self.Position.Y = game.Mouse.Position.Y
So each piece can be moved by dragging and dropping. This seems to work fine.
Now, let me put what I think you said, so please help me see where I'm wrong.
I made a Game Attribute and called it "Busy"
Rule: When All
touch inside
Attribute game.Busy = false
...Change Attribute game.Busy = true
...Rule when All game.Busy = true
......Move
...Rule: When All touch is released
...Change Attribute game.Busy = false
I'm probably not getting the nesting correct. I've tried different things, but when I click on the piece, it doesn't move.
2 game integer attributes:
- ID creator (Value:1)
- WhichID (Value:0)
Attributes inside of actors that you will be moving around:
(all integer attributes)
-ID (0)
-OriginX (0)
-OriginY (0)
-ChangeX (0)
-ChangeY (0)
-OriginTouchX (0)
-OriginTouchY (0)
-----------------------------------------------------------
Change attribute: self.ID to game.IDCreator
Change attribute: game.IDCreator+1
------------------------------------------------------------
RULE:
When touch is pressed:
change attribute: game.WhichID to self.ID
otherwise
change attribute: game.WhichID to 0
--------------------------------------------------------------
RULE:
When attribute game.WhichID=self.ID
change attribute: self.OriginX to self.position.X
changé attribute: self.OriginY to self.position.Y
change attribute: self.OriginTouchX to game.Touches.Touch 1.X
change attribute: self.OriginTouchY to game.Touches.Touch 1.Y
CONSTRAIN ATTRIBUTE: self.ChangeX to game.Touches.Touch 1.X - Self.OriginTouchX
CONSTRAIN ATTRIBUTE: self.ChangeY to game.Touches.Touch 1.Y - Self.OriginTouchY
CONSTRAIN ATTRIBUTE: self.position.X to self.OriginX+Self.ChangeX
CONSTRAIN ATTRIBUTE: self.Position.Y to self.OriginY+Self.ChangeY
I did discover I can move a piece much more simply by just doing this:
Rule:
When All Actor touch pressed
Constrain Attribute self.Position.X to game.Mouse.Position.X
Constrain Attribute self.Position.Y to game.Mouse.Position.Y
So I'm not sure what the purpose of making an Attribute called DragDrop was, or setting an "Otherwise" unless it keeps things clean?
So Artonskyblue, I create 2 game integer attributes, and inside each Actor 7 integer attributes.
Then the behaviors and rules above will move my piece, and not cause them to get stuck to each other when they overlap? I'll have to try it and see what happens. Now I think I need some sleep, I'm up too late! Thanks for the suggestion.
Remember, you dont have to put those rules and attributes in each actor individually. The rules will be the same in each actor, so just copy and paste the actor as many times as you need, and you can change the image of it easily as well
and yeah the self.pos.x/y to mouse.pos.x/y works but that will cause overlapping