Last problem!

jimmyraynorjimmyraynor Member Posts: 22
edited November -1 in Working with GS (Mac)
(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?



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

    Constrain Attribute:
    game.Power to min(2,abs(cos(self.time - self.starttime)*2))
  • jimmyraynorjimmyraynor 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'll go past the screen.
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    Try multiplying the time, not the result of sine:

    min(2,abs(sin((self.time - self.starttime)*2)))
  • jimmyraynorjimmyraynor 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.
  • BarkBarkCoBarkBarkCo 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.
  • jimmyraynorjimmyraynor Member Posts: 22
    ty, that'll really help.
  • BarkBarkCoBarkBarkCo 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:

    A is the equiv of "self.time - self.starttime", and D is the equiv of the expression above
  • jimmyraynorjimmyraynor Member Posts: 22
    works PERFECTLY!
    thanks a lot, i appreciate it.
    that's so genius, i never would have figured that out.
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    Glad I could help.

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