Rotating an actor and maintaining an attribute.
matarua
Auckland, New ZealandMember Posts: 854
I am rotating an actor using buttons and keyboard presses.
I have two attributes that are boolean 'clockwise' and 'antiClockwise'
There is a rule that says if 'clockwise is true : Rotate Clockwise Speed 500.
There is a rule that says if 'antiClockwise is true : Rotate Counter-Clockwise Speed 500.
I then have a button for both directions.
Inside the left button there is a rule that says if Actor receives event: touch is pressed or Actor receives event: key left is down. Constrain Attribute: game.antiClockwise to true
Otherwise Constrain Attribute: game.antiClockwise to false
Inside the right button there is a rule that says if Actor receives event: touch is pressed or Actor receives event: key right is down Constrain Attribute: game.clockwise to true
Otherwise Constrain Attribute: game.clockwise to false
I am displaying text that shows me the value of antiClockwise and clockwise so I know they are working.
When pressing and releasing left the actor rotates antiClockwise - great. When pressing and releasing right the actor rotates clockwise.
Then when keeping left pressed it rotates antiClockwise, and pressing right while left is still pressed the rotation changes to clockwise.
But this is the problem. When releasing right, while still holding left - it should start rotating antiClockwise. But it does not. In fact it gets stuck - and can be set going again on the next press.
I know this is a sequentially dominant thing where one attribute gets served after another and kills the first one. How can I get around that however?
The attribute stays true and it should be rotating, it is being constrained - but it does not.
Any ideas?
Thanks, M@
I have two attributes that are boolean 'clockwise' and 'antiClockwise'
There is a rule that says if 'clockwise is true : Rotate Clockwise Speed 500.
There is a rule that says if 'antiClockwise is true : Rotate Counter-Clockwise Speed 500.
I then have a button for both directions.
Inside the left button there is a rule that says if Actor receives event: touch is pressed or Actor receives event: key left is down. Constrain Attribute: game.antiClockwise to true
Otherwise Constrain Attribute: game.antiClockwise to false
Inside the right button there is a rule that says if Actor receives event: touch is pressed or Actor receives event: key right is down Constrain Attribute: game.clockwise to true
Otherwise Constrain Attribute: game.clockwise to false
I am displaying text that shows me the value of antiClockwise and clockwise so I know they are working.
When pressing and releasing left the actor rotates antiClockwise - great. When pressing and releasing right the actor rotates clockwise.
Then when keeping left pressed it rotates antiClockwise, and pressing right while left is still pressed the rotation changes to clockwise.
But this is the problem. When releasing right, while still holding left - it should start rotating antiClockwise. But it does not. In fact it gets stuck - and can be set going again on the next press.
I know this is a sequentially dominant thing where one attribute gets served after another and kills the first one. How can I get around that however?
The attribute stays true and it should be rotating, it is being constrained - but it does not.
Any ideas?
Thanks, M@
Comments
I am going to re-think it perhaps and not use booleans. Go for a toggle approach. Wish me luck
Add those as rule conditions to where you have the key press. So left with have added if self.right is false. Right will have if self.left. Is false.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Your solution means that when both keys are pressed the box just stops - it will resume rotation once one key is released.
What I am doing successfully with my own code is not working for both directions but it is perfect one way.
So when the player presses left - the box rotates left - the player keeps pressing left and then also presses right - the box rotates right for as long as the player holds the right key - then goes back to rotating left.
So in this case the second key press overrides the first for the time it is pressed but does not turn the other key press off or lockout as you say. I don't want that.
This needs to be reversed for the right side which is why I thought toggling might be the answer.
I can get the effect but it changes sides depending on the order of my logic. It does not work for both sides.
The logic conditions and map would look like this...
0. No input = stopped
1. Left down = rotate CounterClockwise
0. Left up = stopped
2. Right down = rotate Clockwise
0. Right up = stopped
1. Left down = rotate CounterClockwise
2. Right down = rotate Clockwise
1. Right up = rotate CounterClockwise
0. Left up = stopped
1. Left down = rotate CounterClockwise
2. Right down = rotate Clockwise
2. Left up = rotate Clockwise
0. Right up = stopped
(reversed)
2. Right down = rotate Clockwise
1. Left down = rotate CounterClockwise
2. Left up = rotate Clockwise
0. Right up = stopped
2. Right down = rotate Clockwise
1. Left down = rotate CounterClockwise
1. Right up = rotate CounterClockwise
0. Left up = stopped
There could be a chain 0,1,2,1,2,1,2,1,2,1,2,0.
Hopefully this goes some way towards solving it.
It's late here so will sleep on it...
Thanks if anybody can help
Regards, M@
Rule
Key is down left and when self.right is false
Change attribute self.left to true
Change attribute game.clockwise to true
Otherwise
Change attribute game.clockwise to false
Change attribute self.left to false
Rule
Key is down right and when self.left is false
Change attribute self.right to true
Change attribute game.counter to true
.
Otherwise
Change attribute game.counter to false
Change attribute self.right to false
As you can see the other button can't engage until the first button is false so when both are down the first pressed will be chosen locking the other out until it's lifted.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
But...
It locks in the choice, and the other out, and behaves as you intend it I think. But I don't want the button locked out - I want it to override.
Best example I can think of is Super Hexagon if you have that it's what I am trying to achieve with the controls.
Your solution is the most solid so far
It is late here and time for bed - so will attack fresh tomorrow...
Many thanks M@
Make game level integer game.rotate
Rule
When left key is down
Change attribute game.rotate to 1
Rule
When right key is down
Change attribute game.rotate to 2
Rule
All
When left key is up and right key is up
Change attribute game.rotate to 0
Rotating actor
Rule
When game.rotate = 1
Rotate left
Rule when game.rotate = 2
Rotate right
By using one integer and a change attribute the rule will fire when pressed and not fire again until released and pressed again. So when you press one it changes to one. Then when you press the other it changes to two. It can never be both.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Rule
When left key is down and Game.rotate = 0
Change attribute game.rotate to 1
Rule
When right key is down and Game.rotate = 0
Change attribute game.rotate to 2
Rule
(ANY)
When left key is up and right key is up
Change attribute game.rotate to 0
Rotating actor
Rule
When game.rotate = 1
Rotate left
Rule when game.rotate = 2
Rotate right
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
When right key is up & When left key is up
-- Change Attribute: self.rotationSpeed To: 0
When right key is down
-- Change Attribute: self.rotationSpeed To: -100
When left key is down
-- Change Attribute: self.rotationSpeed To: 100
When left key is up & When right key is down
-- Change Attribute: self.rotationSpeed To: -100
When right key is up & When left key is down
-- Change Attribute: self.rotationSpeed To: 100
Rotate
-- Direction: Counter-clockwise
-- Speed: self.rotationSpeed
@FryingBaconStudios I will try yours next... after lunch.
P.S. the exclusive switching code is going to be helpful if not for this for something else. Much appreciated!
- thanks so much for your help guys - simple proof of concept for a game one step closer.