How to make a power-up float?

FrazzleFrazzle Member Posts: 223
edited May 2012 in Working with GS (Mac)
I'm wondering how do you make an object float like how power-ups usually do, with them slowly moving up and down. I'm guessing this requires use of interpolate but I'm not sure if thats the best way. Any help is appreciated.
Cheers, FM.

Answers

  • simo103simo103 Member, PRO Posts: 1,331
    edited May 2012
    you could try constraining self.positionY to (100*sin(self.time*100))+400

    first 100 is the range of movement ie 100 up/down. Second 100 is the speed and +400 is the starting position
  • jckmcgrawjckmcgraw Member Posts: 647
    @Frazzle

    Interpolate is good.

    Rule: when self.pos.y > (top bobbing spot), interpolate self.pos.y to (bottom bobbing spot)

    Rule: shen self.pos.y < (bottom bobbing spot), interpolate self.pos.y to (top bobbing spot)

    You can adjust duration to however long you want it. Make sure the starting pos of the powerup is above the top bobbing spot or below the bottom bobbing spot so that one of the interpolate rules will be triggered. Also, if you want it to really bob nicely, you can set the interpolate to ease in or ease out.

    Hope this helps,
    Jack McGraw
  • simo103simo103 Member, PRO Posts: 1,331
    and as a 'rule of thumb' if one of the posts is from tsb ... then you have your answer! lol .... was just happy to use trig in an answer.
  • FrazzleFrazzle Member Posts: 223
    Thanks for the responses!
    Tshirtbooth's suggestion is exactly what I had it setup, so it's nice to know thats a good way to do it XD. Thanks for the help guys,FM.
  • simo103simo103 Member, PRO Posts: 1,331
    if I could add something to help further .... I found on a couple of occasions that my interpolate rules didn't work because I specified the exact number for it to react to .. ie: if self.positionX=100 then interpolate etc. The reason appeared to be that the actor moved to position 100.123 or something like that .. so I often use greater than or equal to OR less than or equal to to catch that. (Happened to me a few times and might have been poor coding elsewhere but a display text verified the X value as not being exactly 100). Can't hurt to set it that way ..
Sign In or Register to comment.