Advanced Gas Pedal Question...
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!
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
when pressed, TIMER every 0.001 change attribute "gas" to "gas+1"
-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
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))
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS