Last problem!
jimmyraynor
Member Posts: 22
(I think it's the last problem)
Hi all,
In the cannon template, the power is modeled by...
Constrain attribute
game.Power to min (2, self.time - self.starttime)
Then, the power bar actor has 2 behaviors ...
Constrain attribute
self.size.height to 158*game.Power
Constrain attribute
self.position.Y to self.size.height/2
If the player holds down the fire button .. it goes to the top and just stays there (because the min rule always takes 2).
I want it to loop, so that if the player holds for 2.5 seconds its now 1.5, if 3 seconds, its now 1 second.. and 4 seconds would be 0 seconds. 5 seconds would be 1 second, etc.
How can I alter the rules/behaviors for the power to loop this way?
Thanks!
Hi all,
In the cannon template, the power is modeled by...
Constrain attribute
game.Power to min (2, self.time - self.starttime)
Then, the power bar actor has 2 behaviors ...
Constrain attribute
self.size.height to 158*game.Power
Constrain attribute
self.position.Y to self.size.height/2
If the player holds down the fire button .. it goes to the top and just stays there (because the min rule always takes 2).
I want it to loop, so that if the player holds for 2.5 seconds its now 1.5, if 3 seconds, its now 1 second.. and 4 seconds would be 0 seconds. 5 seconds would be 1 second, etc.
How can I alter the rules/behaviors for the power to loop this way?
Thanks!
Comments
Constrain Attribute:
game.Power to min(2,abs(cos(self.time - self.starttime)*2))
min(2,abs(sin((self.time - self.starttime)*2)))
The only thing is.. the speed slows down noticeably towards the top (since its the top of the sin graph loop too). So overall, the speed isn't constant, but I guess that won't be such a big deal.
Below is a chart that breaks the logic in to parts:
http://i50.tinypic.com/2nuonpw.png
A is the equiv of "self.time - self.starttime", and D is the equiv of the expression above
thanks a lot, i appreciate it.
that's so genius, i never would have figured that out.
I didn't test any of this in GS yet, but based on the math, it should loop through completely every 4 seconds. If you want it to go 2x its current speed, take out the "/2" parts. That will make it loop through the whole range of motion in 2 secs as opposed to the current 4 secs.