Measure rotation in unlimited degrees

I've been working with gamesalad before where the rotation attribute returns degrees without going back to 0 after 359. For instance, two clockwise revolutions would return 720. Two counter-clockwise revolutions would return -720.

I need to be able to do it this way again.

Right now it's returning it in degrees like an angle variable even though I'm storing it as real.

Answers

  • mataruamatarua Auckland, New ZealandMember Posts: 854
    This is the default behaviour and should just happen - you have to modulate the rotation by %360 to get it to loop - so if you have that modulation in your equation just remove it and you will get the true rotation value.

    Is that correct?

    Cheers, M@
  • ProjectorXProjectorX Member Posts: 45
    Yes this was my understanding but all I'm doing is constraining the rotation directly to a (real) game variable and it's acting as though I'm using mod(x,360) on it.
  • SocksSocks London, UK.Member Posts: 12,822
    Like this ?
  • SocksSocks London, UK.Member Posts: 12,822
    Yes this was my understanding but all I'm doing is constraining the rotation directly to a (real) game variable and it's acting as though I'm using mod(x,360) on it.
    If the variable goes to 1420 the rotation should be 1420 ?
  • ProjectorXProjectorX Member Posts: 45
    Oops I meant I'm constraining the game variable to the rotation, not the other way around.
  • ProjectorXProjectorX Member Posts: 45
    Even when I copy your exact display text behavior over, it still loops back to zero.
  • SocksSocks London, UK.Member Posts: 12,822
    Oops I meant I'm constraining the game variable to the rotation, not the other way around.
    Works fine for me
  • ProjectorXProjectorX Member Posts: 45
    Ok I narrowed it down to the fact that I'm constraining self.rotation to self.rotation +- 2 instead of using a rotate behavior. You'd think that would work but, oh well. How constraining!

    Now, though, while I have you here, the new problem is that rotate to angle only rotates counter-clockwise.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    What angle are you starting with and what angle are you rotating to? I can get Rotate to Angle to go either direction.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Member Posts: 12,822
    What angle are you starting with and what angle are you rotating to? I can get Rotate to Angle to go either direction.
    Same here (see attached file).

    I think the problem here (in working out the issue) is that there is so little information supplied, nothing is put in any context, all we can do is make guesses as we can't see the code that is causing this issue.
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    The angle - when using rotate to angle is automatically modulated and takes the shortest path to the destination.

    So rotate to angle 179 from 0 is anticlockwise.

    Rotate to angle 181 from 0 is clockwise.

    Without a detailed explanation with sample code or the sample project it's difficult to give a good solution on here sorry.

    Cheers, M@
  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2013
    The angle - when using rotate to angle is automatically modulated and takes the shortest path to the destination.

    So rotate to angle 179 from 0 is anticlockwise.

    Rotate to angle 181 from 0 is clockwise.
    Then you could simply use an interpolate along with a rotate to angle - with the target angle being the interpolation value. . . . . I think !? . . . . . . hold on let me test that . . .
  • SocksSocks London, UK.Member Posts: 12,822
    Example:

  • SocksSocks London, UK.Member Posts: 12,822
    . . . then again if you are interpolating a value for the rotate to angle behaviour you might as well cut out the middle-man and simply interpolate to the desired angle . . . ?

    Example V2:

  • SocksSocks London, UK.Member Posts: 12,822
    basically, this is a much better 'rotate to angle' behaviour . . .

    image
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    edited November 2013
    Wacky @Socks - cool man - at least we are having some fun learning here eh ;)
  • SocksSocks London, UK.Member Posts: 12,822
    Wacky @Socks - cool man - at least we are having some fun learning here eh ;)
    Yep ! :)>-
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    You can also us a negative angle with interpolate to go in the opposite direction. I believe you can even interpolate to an angle higher than 360 or lower than -360 for that matter. I'm on my phone so I can't test that theory at the momment.
  • SocksSocks London, UK.Member Posts: 12,822
    edited November 2013
    You can also us a negative angle with interpolate to go in the opposite direction. I believe you can even interpolate to an angle higher than 360 or lower than -360 for that matter. I'm on my phone so I can't test that theory at the momment.
    Yes, you're quite right ! That's what's in the image above (and the attached file), you can interpolate to whatever you like as you are not really interpolating to an angle, just to a value (which is then used as the angle).
  • ProjectorXProjectorX Member Posts: 45
    Is there a way I can upload a .gameproj or do you have to have a subscription for that?
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    You might have to use dropbox - zip it up and share the public link.

    Cheers, M@
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Pro members can attach .zip files. Anyone can post a link to a hosted file using a service such as Dropbox.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • ProjectorXProjectorX Member Posts: 45
    Ok, here it is. I tried to simplify it as much as possible.

    https://www.dropbox.com/s/ebdnczi00ryix6p/Rotate to Angle.gameproj.zip

    You can find the behaviors in question in the white "car" actor in the top group called "Issue". And there are a couple different solutions to achieve the desired effect, but they all have the same problem: they want to take the long way around.

    There are two actors so that one can rotate to the angle of the other. The other's angle is dynamic and can change. The white car rotatoes to the angle of the red car.

    Left Arrow - Rotate white car CCW
    Right Arrow - Rotate white car CW

    Hold down UP arrow to change the rotation of the red car.
    The angle - when using rotate to angle is automatically modulated and takes the shortest path to the destination.
    For some peculiar reason it does the opposite..sometimes.

  • mataruamatarua Auckland, New ZealandMember Posts: 854
    Hey there, got the project thanks - what do you actually want to achieve however?

    What happens to the car? Is it like this?

  • ProjectorXProjectorX Member Posts: 45
    Yeah that except with drift and stuff.

    I find it peculiar that if Rotate to Angle is in fact supposed to take the shorted path that, even with the rotations clearly displayed, it clearly doesn't.
  • ProjectorXProjectorX Member Posts: 45
    I've tried eliminating all the other rules / behaviors and it still won't rotate right.
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    So are you making a drift racing game? And one car follows the other? Sounds like an AI thing that could be quite complex.

    I have a game where I have an object rotate and it works on key presses and also touches etc. that could emulate the cars from micromachines if you added some acceleration based on the self.rotation direction.

    With this if you key press down left it goes anti clockwise and the opposite for right - if one is down and you press the other it overrides then goes back.

    If you let go at 120 degrees it will just stay there however.

    From your project it seems like you want the car to always go back to 0 degress tho?

    Is that right?

    Cheers, M@
  • mataruamatarua Auckland, New ZealandMember Posts: 854
    You can download this template for 10 Quid...

    http://www.deepblueapps.com/gs-racerz-template/

  • mataruamatarua Auckland, New ZealandMember Posts: 854
    @ProjectorX they have 40% off templates @DeepBlueApps at the moment too :)
Sign In or Register to comment.