Rotating an actor and maintaining an attribute.

mataruamatarua 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@





Comments

  • mataruamatarua Auckland, New ZealandMember Posts: 854
    Hey there - I have semi-solved this but I need to toggle things somehow - I know how to toggle but with all this code it's a boggle.

    I am going to re-think it perhaps and not use booleans. Go for a toggle approach. Wish me luck :)
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited September 2013
    You need a lockout of the other key. So first don't constrain booleans use change attribute. Add two self attributes to where your key controls are. Booleans will work. One is self.left key the the other self.right.key. When left is down change to true otherwise false same for the other.

    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.

  • mataruamatarua Auckland, New ZealandMember Posts: 854
    Cheers mate - will have a go with that - I have two very close calls doing nearly exactly what I want at the moment. Will give this a bash... thanks.
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    @FryingBaconStudios I have got all three versions of logic working now - and they all behave differently.

    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@

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited September 2013
    Maybe I didn't explain it right. I use the method in my two button jump and run controls. So your key which triggers the booleans for rotate should look like this.

    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.
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    Ok thanks for the clarification - it's working better now :)

    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@
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Um yeah I'd have to give that some thought as that's going to send conflicting commands. In that case I would use a single integer for the rotate. So try this.

    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.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    if that doesn't get you there modify it like this.

    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
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    Give this a try:

    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
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    I am up watching New Zealand in the Americas Cup - time to try these ideas - thanks guys :)
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    @RThurman solved it - great thanks - I will now replicate that with some attributes to bring it to the touch screen.

    @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.
Sign In or Register to comment.