# Last problem!

Member Posts: 22
edited November -1
(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!

• Member Posts: 1,400
Try this on power...

Constrain Attribute:
game.Power to min(2,abs(cos(self.time - self.starttime)*2))
• Member Posts: 22
I did try that with sin (starting point 0 then), but the power bar rises very very slowly. How can i Increase that? If i change 2 to like 20, it won't loop..it'll go past the screen.
• Member Posts: 1,400
Try multiplying the time, not the result of sine:

min(2,abs(sin((self.time - self.starttime)*2)))
• Member Posts: 22
Hey, that works really well. It now loops at a fast speed, thanks!
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.
• Member Posts: 1,400
I have a solution that uses two parallel yet invert mod(%) functions nested within a min function. I'll explain more later.
• Member Posts: 22
ty, that'll really help.
• Member Posts: 1,400
`MIN(((self.time - self.starttime)/2)%2,2-(((self.time - self.starttime)/2)%2))*2`

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
• Member Posts: 22
works PERFECTLY!
thanks a lot, i appreciate it.
that's so genius, i never would have figured that out.
• Member Posts: 1,400