Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Last problem!

jimmyraynorjimmyraynor Posts: 22Member
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 Posts: 1,400Member
    Try this on power...

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

    min(2,abs(sin((self.time - self.starttime)*2)))
  • jimmyraynorjimmyraynor Posts: 22Member
    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 Posts: 1,400Member
    I have a solution that uses two parallel yet invert mod(%) functions nested within a min function. I'll explain more later.
  • jimmyraynorjimmyraynor Posts: 22Member
    ty, that'll really help.
  • BarkBarkCoBarkBarkCo Posts: 1,400Member
    `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 Posts: 22Member
    works PERFECTLY!
    thanks a lot, i appreciate it.
    that's so genius, i never would have figured that out.
  • BarkBarkCoBarkBarkCo Posts: 1,400Member
    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.
This discussion has been closed.