Advanced Gas Pedal Question...

gamesfuagamesfua Member Posts: 723
edited November 2012 in Working with GS (Mac)
Hey all, thanks for helping out!
I couldn't find a great answer to a quick question I have. I'm making a game that requires acceleration when the user holds the gas down. When the user releases, the object eventually slows down. I have a working model of it but I'm not entirely sure if it's the most effective way of doing it. I'm using a ton of constraints and I know how that's not always the best idea. Here's how I currently have it.

Here Goes:
-real attribute called "gas"
-rule that says when user touches pedal/button, constrain "gas" to "gas+1" (this is to increase the speed as user holds button)
-when release, constrain attribute "gas" to "gas-1" (*This is to bring the speedometer and speed down.)
-(to ensure the speedometer doesn't go past 100 or it's minimal 0, I have the following rules)...
- RULE if "gas" is greater than 100, constrain "gas" to 100
- RULE if "gas" is less than 0, constrain "gas" to 0.

So how does that look? There's got to be an easier and more efficient way of doing this. And also one more thing. For whatever reason in my above setup, when I test the game and PRESS THE GAS BUTTON, it initially will only ADD 1 to the GAS and then stop there. Then when I PRESS IT AGAIN, it finally starts to CONSTRAIN the continually adding GAS numbers. Why is that?

A million thanks with whatever help you can give!

Comments

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Sounds like you might want to experiment around with the accelerate behavior on an actor. Often you can use the accelerate behavior in conjunction with changing the actor's drag to get the effect you are describing.
  • gamesfuagamesfua Member Posts: 723
    @RThurman thanks but thats what i'm doing. My actor has an acceleration behavior BUT needs to be effected by a gas pedal. I also want the speedometer to mark the speed. Hence why i used the game logic above with constraints. What i'm looking for is if my game logic is good or if there's another way to do it (perhaps with min max or magnitude values for the speed etc.) But thank you very much @RThurman- you're very right acceleration and drag are really great tools.
  • LooseMooseLooseMoose Member Posts: 224
    edited November 2012
    If you changed you pedal behaviour to this would it remove the problem of having to tap it twice?
    when pressed, TIMER every 0.001 change attribute "gas" to "gas+1"
  • LooseMooseLooseMoose Member Posts: 224
    Also instead of using those constraints for max and min speed could you just use the change attribute function to save performance?
  • gamesfuagamesfua Member Posts: 723
    @Kyukon, thanks! But I'm pretty sure the change attribute won't work because the gas constrain attribute will probably override it. I could be wrong, but I think that's right. Thanks for the tip with the TIMER. I may have to resort to that. I'd love to know why it's doing that though. Thanks again guys. ANyone else have any ideas or is this game logic i presented solid?
  • LooseMooseLooseMoose Member Posts: 224
    I think you could probably replace all of those constraints with 'change attribute'.

    -when pressed, TIMER every 0.001 change attribute "gas" to "gas+1"
    -when pressed, TIMER every 0.001 change attribute "gas" to "gas-1

    - RULE if "gas" is greater than 100, change attribute "gas" to 100
    - RULE if "gas" is less than 0, change attribute "gas" to 0.

    It might not work for you but thought I'd suggest it anyway. Goodluck
  • gamesfuagamesfua Member Posts: 723
    Thanks Kyukon, great alternative tip. I'll give that a go :)
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    It is strange that it takes two touches to get the constrain to work! Thats got me stumped.

    Here is another variation on @Kyukon 's timer theme:

    When touch is pressed
    -- Timer every 0 seconds
    ---- Change Attribute self.Gas To: min(100,(self.Gas +1))
    otherwise
    -- Constrain Attribute: self.Gas to: max(0,(self.Gas -1))
  • gamesfuagamesfua Member Posts: 723
    Yeah @RThurman I have no idea why it takes two taps. It seems like it needs one time to register it or something. Anyways thanks for your alternative tip!
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    It works well (but I don't know about efficiency). It gets rid of the two rules (with the min/max functions) and it does override the double touch issue.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    How about using max velocity in the actor preferences?
  • gamesfuagamesfua Member Posts: 723
    @FryingBaconStudios can you explain more? Is that different than max speed?
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Sorry meant max speed. then you could just use one half to accelerate and that attribute already in the system would regulate the top speed.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    You might want to look at the joystick free template in the GS file window.
  • gamesfuagamesfua Member Posts: 723
    Just a heads up I have come up with a solution to one of my problems. The targeted issue of why when I press the gas pedal, that it only adds 1- and then when i press it again it finally does what its supposed to (constrain-constantly adding 1 like acceleration). The work around was to attach a boolean to the button. So now when I press the button it says TRUE. When not, FALSE. The a rule that says when TRUE, constrain gas+1. When FALSE constrain gas-1. Fixed it! Anyways thanks to everyone in here for the help. Always a pleasure listening to all of your great tips, tricks, etc. Thanks again!
Sign In or Register to comment.