Rotate on button press

TangoDownStudiosTangoDownStudios Member Posts: 46
edited November -1 in Working with GS (Mac)
I would like to add rotational velocity to an object when I press a button. Seems simple enough right? But the caveat is I want it to be smooth and constant as long as the button is held down.

When the left button is pressed for instance I want an object to rotate to the left and continue rotating at a fixed speed until the left button is depressed.

I've tried to add rotational velocity (self.motion.angularvelocity=self.motion.angularvelocity+5.0) but it only does it once, then I have to press the button down again. Is there any way of continuously applying this?

Comments

  • AsymptoteellAsymptoteell Member Posts: 1,362
    Use constrain to 50.
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    This will allow me to continually rotate at 50 yes, but I'd like to start at 0, and then work my way up to 50
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    Youll want to have your attribute for when the buttons pressed, ill call it rotate. In the button have when touch is pressed change rotate to 1, and a rule when touch is released change rotate to 0. In the actor you want to rotate have a rule when attribute rotate =1 interpolate attribute angular velocity to 50, and select ease in instead of linear from the drop down. then have another rule when attribute rotate =1 ANd when attribute angular velocity =50 constrain angulare velocity to 50
  • RodericRoderic Member Posts: 145
    Tango, Just a thought. What about adding a timer to the rule to add rotational velocity every second for X number of seconds. Would that work?
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    Roderic said:
    Tango, Just a thought. What about adding a timer to the rule to add rotational velocity every second for X number of seconds. Would that work?

    You can also do that, in the post i made above the rule when attribute rotate=1 interpolate to 50, you can take the interpolate out and put a timer with every .2 seconds change attribute angular velocity to angular velocity +1.

    Try both out and see what works for you

    cheers
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    Oh wow! Thats great thinking! I tried it, AND it works : ) Trying to tinker with getting it to NOT finish interpolating to 50 if the button is no longer depressed...

    Hope I can find an answer before someone else posts it here (Would be greatly appreciated though)

    And major props to JohnPapiomititis for his grand help!
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    I tried the adding rotational velocity with a timer, but for whatever reason the rotationalVelocity will not increment! It will initially gain the velocity assigned inside the timer and start rotating, but it will not continue to gain velocity as I hold the button down. And I made sure I have the "Every" timer function set not "After" or "For"
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    TangoDownStudios said:
    Oh wow! Thats great thinking! I tried it, AND it works : ) Trying to tinker with getting it to NOT finish interpolating to 50 if the button is no longer depressed...

    Hope I can find an answer before someone else posts it here (Would be greatly appreciated though)

    And major props to JohnPapiomititis for his grand help!

    Glad i could help. And putting a rule in whatevers rotating when attribute rotate =0 constrain attribute angular velocity to 0 should stop it after you let go
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    I like the idea of stopping the rotation after I let go of the button via checking for rotate=0, but I like the idea of conserving rotational momentum instead of killing it all better. I'd like to slowly slow down after I stop pressing the button, and I really think timers would work great. But for some reason timers... don't work very well.

    When I set a timer with an interval of 0.2 to increment the rotationalVelocity value I get a very undesired slow moving effect and the rotationalVelocity does not increment correctly. Say I increment +5 to the rotationalVelocity: the object will start rotating at 0.2 velocity and go back to 0, then 0.2 seconds later will start rotating at 0.2 velocity again and this will continue until I depress the key
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    John, would I be able to perhaps email you the issue I'm trying to fix? Its a very simple project and hopefully you could point out my errors
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    sure my emails papiomitis@yahoo.com
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    Thank you John! I've sent you the email, also I'm working on publishing this test to GameSalad so others can take a look at it, both before and after it is fixed
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    Actually just do this haha i just tested it will work.

    Instead of having when attribute rotate =0 constrain attribute angular velocity to 0, have this:

    Have a rule When attribute rotate = 0

    in that rule interpolate self angular velocity to 0, with ease out selected

    then another rule seperate from that one when attribute rotate =0 AND attribute self angular velocity =0 constrain self angular velocity to 0

    Leave all the rules to start and interpole the rotation when rotate = 1 the same, that should do it for ya
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    "Rotate Object" is not on the new list for games! Please check it out if you are reading this forum and see if you can get it to work with timers!
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    http://www.mediafire.com/?0bhnb1tkv211c6v

    theres the fixed project for ya

    cheers
  • TangoDownStudiosTangoDownStudios Member Posts: 46
    Thanks again John! I looked over your project but I think I found a way that works just as well (If not better) and it uses just one more global variable. I uploaded it again to the GS repository so if anyone wants to take a look its called "rotate object" and it has a nice flashy icon that I made in PS lol.

    Thanks for all your help!
Sign In or Register to comment.