Free Yourselves From The Tyranny of Center Only Rotations!

RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
edited November -1 in Working with GS (Mac)
Tired of that run-down feeling? Images not as bright and cheerful as they used to be? Are your rotating actors feeling a little dull and listless?

Well then, we have the formula for you!

Announcing the new and improved "Off Center Rotation" equations. That's right! Now your actors can rotate in any direction, and from any point on (or off) the actor!

Whats that?!? How is that possible you ask?

Well -- thanks to the miracle of modern science and the good folks at GameSalad (who provided an equation editor complete with magnitude, sin, and atan functions), we proudly present the following:

self.position.x = game.sceneX-magnitude( self.offsetX , self.offsetY )*sin(( self.Rotation )-atan( self.offsetX / self.offsetY ))
self.position.y = game.sceneY+magnitude( self.offsetX , self.offsetY )*cos(( self.Rotation )-atan( self.offsetX / self.offsetY ))

Thats right! With these equations you can change and/or constrain the x and y coordinates of any actor so it rotates around the x and y offsets you specify. You just need to say where in the scene the actor is supposed to be (sceneX and sceneY), the spot on the actor (from its center) where you want it to rotate (offsetX and offsetY), and the rotation angle (self.Rotation). You can leave everything else as is!

Whats the cost, you ask?

Well -- with as little down as four attributes (screenX, screenY, offsetX, offsetY) you can be in business for yourself.

Can it be true?

Yes! Imagine what you can do. You can have pinball flippers and tank turrets that rotate where they are supposed to! You can have pictures that hang, and wheels that wobble off-center. And best of all… no more extra dead space on your actors to get in the way of things.

Go ahead! Give it a try! What have you got to lose?!?!
«13

Comments

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    Disclaimer:
    If the above solutions are common knowledge then my apologies. I looked high and low to find how to rotate things off-center in GameSalad, but I couldn't find any information like this on the forums.

    I had fun learning how to do this and just needed to crow a little!
  • quantumsheepquantumsheep Member Posts: 8,188
    Hey,

    That's some great stuff right there! Thanks for sharing, I'm sure it'll be useful!

    QS :D

    EDIT - Also, it might be worth adding this to the cookbook as a question and answer thingy :)

    DOUBLE EDIT - oh, and it was entertainingly written! How to make equations fun - who'd have thunk it? :D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • DreamLabDreamLab Member Posts: 2,127
    Great stuff! you have been a great help!
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    quantumsheep said:
    Hey,

    That's some great stuff right there! Thanks for sharing, I'm sure it'll be useful!

    QS :D

    Hey -- you're welcome. I've found it very useful for trimming out all the extra space that was needed to get 'the center' in just the right spot.
    DreamLab said:
    Great stuff! you have been a great help!

    Thanks -- I do hope that this is helpful. It looks a little complicated at first. But its really just a matter of plugging in some x and y coordinates.

    RThurman
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Just giving this great tip a bump for the morning crowd.

    @RThurman - Very nice. Good to see we have a new math wiz we can lean on ;)
  • old_kipperold_kipper Member Posts: 1,420
    Wicked. Thanks! All my wheels will now wobble with wondrous grace and efficiency. Any thoughts on inertia and somewhat non-vanilla magnitude triggers...? (he muttered out of pure self interest)

    cheers kipper
  • 11clock11clock Member Posts: 450
    Bookmarking this. This sounds very useful. Thanks!
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Wow, excellent stuff! You've a right to "crow" as you put it. Thanks a lot, that will be useful for me too. :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • LaurenSaladLaurenSalad Inactive, Chef Emeritus Posts: 650
    This is really great information!

    I would like to echo Quantum Sheep and ask that you put this into Cookbook so there will be a lasting record of this question/answer.

    If you are unfamiliar with Cookbook- GameSalad Cookbook is a Q&A environment where developers can ask and answer questions about GameSalad Creator, Viewer, HTML5 and iOS publishing, and other GameSalad-related issues.

    In Cookbook, you can search for existing questions, rate other developer’s answers up or down, add tags, follow questions, share video, screenshots, templates, and much more!

    Thanks again for the awesome (and hilarious) post, RThurman!
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    tenrdrmer said:
    @RThurman - Very nice. Good to see we have a new math wiz we can lean on ;)

    Thanks! But I'm afraid that I can't claim any math skills. I just did a Google search for rotating sprites (and hoped to find the right formulas). Funny thing was that the other platform where I found the best answers were because their sprites had the 0,0 point in the upper left corner and they were trying get things to rotate in the center! Go figure!

    RThurman
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    old_kipper said:
    Wicked. Thanks! All my wheels will now wobble with wondrous grace and efficiency. Any thoughts on inertia and somewhat non-vanilla magnitude triggers...? (he muttered out of pure self interest)

    cheers kipper

    You are welcome! I was going to just post the formulas, but then in a moment of inspiration I thought of old-time commercials. I thought it would be fun to put some 'spin' into the posting.

    You may need to give a little more detail about your thoughts on inertia and magnitude triggers. Are you interested in working out orbital mechanics and gravity wells? A little more detail would be helpful.

    RThurman
  • old_kipperold_kipper Member Posts: 1,420
    PM sent.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    11clock said:
    Bookmarking this. This sounds very useful. Thanks!

    gyroscope said:
    Wow, excellent stuff! You've a right to "crow" as you put it. Thanks a lot, that will be useful for me too. :-)

    Glad you feel it will be useful! I think it will give developers a chance to get a little more creative.

    General question: How do you upload demos to GameSalad? I thought I'd put a demo out there. Is there a link to instructions somewhere?

    RThurman
  • SAZ_1SAZ_1 Member Posts: 397
    wait im trying to get an actor to collide with a rotating actor so that when it happens they attach and rotate together (kind of like the way the nut attachs to the tree bit in Poms new game)...is this representing that becuase im struggling for some reason
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    LaurenSalad said:
    I would like to echo Quantum Sheep and ask that you put this into Cookbook so there will be a lasting record of this question/answer.
    ...
    Thanks again for the awesome (and hilarious) post, RThurman!

    LaurenSalad,

    Thanks!
    OK -- I will try to put this into the Cookbook.
    Also, it would be great if you could help make the need to have it in the Cookbook obsolete! Perhaps you could pass on the the interface developers a request to include this in the three rotate behaviors. They would need to add two input fields as the following illustration indicates.

    image

    (I was going to Photoshop the input fields into the other two rotation behaviors, but I think the idea is plain enough.)

    It would be great if users could simply input the offsets and then GameSalad did the off-center rotations automatically. (Thus rendering this thread obsolete!)

    RThurman
  • RodrigoPerezRodrigoPerez Member Posts: 212
    Thanks, this is good stuff, I can see putting this into use for a game idea.

    _______________________________________________________________________

    Photobucket

    Here’s Gameplay Video of Bouncing Birds!
  • ct.ceismcct.ceismc Member Posts: 14
    I know I am a little slow but could you please show us a full example of rotating a long bar about one end like a flipper. When I setup a constrain X & Y to the formulae provided with an offset in the x direction equal to 1/2 the actor's width and then very self.rotation angle I still see a rotation about the center. What am I missing? Thanks for the great information!
  • perseusspartacusperseusspartacus Member Posts: 5
    RThurman said:
    self.position.x = game.sceneX-magnitude( self.offsetX , self.offsetY )*sin(( self.Rotation )-atan( self.offsetX / self.offsetY ))
    self.position.y = game.sceneY+magnitude( self.offsetX , self.offsetY )*cos(( self.Rotation )-atan( self.offsetX / self.offsetY ))

    Are these Constrain Attribute behaviors or something else? I would assume Constrain Attribute, but I just want to make sure.

    EDIT: I also forgot to mention, what value should SceneX and SceneY be? I know what OffsetX and OffsetY should be, but not SceneX and SceneY.

    DOUBLE EDIT: Final note. Do I need an additional rotate behavior or to set the attribute self.Rotation to something bigger than 0?
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    perseusspartacus said:
    Are these Constrain Attribute behaviors or something else? I would assume Constrain Attribute, but I just want to make sure.

    EDIT: I also forgot to mention, what value should SceneX and SceneY be? I know what OffsetX and OffsetY should be, but not SceneX and SceneY.

    DOUBLE EDIT: Final note. Do I need an additional rotate behavior or to set the attribute self.Rotation to something bigger than 0?

    Yes you would be constraining the positions to those expressions. If you plan to have something always movable.

    All attributes should be real.

    And yes you need to have a separate set of rules controlling self.rotation. Either a rotate behavior or interpolate or change. Whatever your flavor.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    ct.ceismc said:
    I know I am a little slow but could you please show us a full example of rotating a long bar about one end like a flipper. When I setup a constrain X & Y to the formulae provided with an offset in the x direction equal to 1/2 the actor's width and then very self.rotation angle I still see a rotation about the center. What am I missing? Thanks for the great information!

    I would guess that if it is rotating about the center then the x and y equations are probably evaluating to 0. This might happen if you typed in the attributes and functions -- instead of using the pull down menus.

    OK -- I just made this one from scratch. I started with a plain actor on the scene. I stretched its length to about 200 and its height to about 30. (It is facing 0, that is, it is pointing right.) Then I added the following rules to the actor.

    image

    The actor then rotates "like a flipper" (well, to me it rotates more like a radar).

    Notice the offsetX and offsetY attributes (in the attribute box). The offsetX is set to 100 and the offsetY is set to 0. These will tell the "flipper" use the left end as the pivot point.

    Also notice the 240 and 160. Those are the x and y coordinates for the scene.

    I do hope this helps!

    RThurman
  • ct.ceismcct.ceismc Member Posts: 14
    Thank you very much. A missed parenthesis makes a huge difference ;-) Surprisingly GS doesn't throw an error with an invalid expression - it just doesn't work. Fortunately if you try and display an invalid expression GS will display "Invalid Expression" in place of the expression result. It sure would be nice if the error checking was built into the expression editor itself. Right now it seems as though the expression editor will take anything you put in there - valid or invalid.

    BTW, it would seem that the formula would blow up when self.offsetY was set to 0 since you are dividing by it (atan(self.offsetX / self.offsetY)) - but it doesn't seem to affect GS. How can this be? What is GS doing when it encounters a divide by 0 statement?
  • ct.ceismcct.ceismc Member Posts: 14
    One last question - Does it work for negative Y offsets? - that is a rotation point above the center-point (game.sceneY) where the object is initially located?

    My tests don't seem to work properly with -Y offsets hence you cannot rotate about the upper right or left corners of the object unless you start with an initial self.rotation setting of 180 for the object placing it upside down. Otherwise if you set a -Y offset the initial position of the object is moved up on the Y axis by the Y offset value and it then rotates about a rotation point below the object.

    A -X offset makes the rotation point be to the right of the object as you would expect but a -Y offset does not work as expected.

    What I am trying to do is work out offsets for rotation about all 4 corners of an object and I can't seem to find anything that works for rotation about the upper right and left corners of an object.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    ct.ceismc said:
    Does it work for negative Y offsets? - that is a rotation point above the center-point (game.sceneY) where the object is initially located?

    My tests don't seem to work properly with -Y offsets

    Hey! Good catch!

    The equations do change slightly when the Y offset is negative. You would need to reverse the first addition/subtraction within each each equation.

    If offsetY is negative -- change the equations to:
    240-(the rest of the x equation)
    160+(the rest of the y equation)

    If offsetY is positive -- change them to:
    240+(the rest of the x equation)
    160-(the rest of the y equation)

    (Note -- 240 and 160 are arbitrary screen coordinates. You can change these numbers to any scene coordinate you want the object to rotate around.)

    Thanks for catching this!

    RThurman
  • dashnevadadashnevada Member Posts: 58
    I would highly appreciate if someone could make a demo out of this and upload it
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    dashnevada said:
    I would highly appreciate if someone could make a demo out of this and upload it

    I'm not sure how to publish a demo to GameSalad. It's probably a no-brainer, but I can't seem to find any documentation. Evidently, I fail at search.
  • marksmarks Inactive, Chef Emeritus Posts: 14
    RThurman said:
    I'm not sure how to publish a demo to GameSalad. It's probably a no-brainer, but I can't seem to find any documentation. Evidently, I fail at search.

    Hey RThurman,

    Navigate to Cookbook (click above, or go to cookbook.gamesalad.com). Log in. Scroll down. Click "add new question" at the bottom of the left-hand column. Enter your question title and content. Upon clicking "create", you should be shown your question with an answer box below it. Enter any information you like there; included are options to link videos or embed screenshots and other media.

    If you have any questions, let me know!

    I've passed along the feature suggestion to our Executive Producer - she thinks it's a great idea, and is going to add it to our backlog of suggested features. Please go ahead and add it to Cookbook as well; it may take a few months before we get to it.
  • Rob2Rob2 Member Posts: 2,402
    I think

    x=distance*(cos(angle))
    y=distance*(sin(angle))

    is a more direct route and you shouldn't have problems with negatives :)

    http://gamesalad.com/forums/topic.php?id=20867
  • CaptFinnCaptFinn Member Posts: 1,828
    To the GS Dev Team. This lil work around does not..... "DOES NOT" mean that we dont want you to fix it so we can simple pick a corner or side or move the center dot. To pic and chose rotation spot. "Work arounds are work arounds" Im sure GS dev team can make this much much a easier task. Not a bad idea and some awesome math. But still..............its a work around.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    Rob2 said:
    I think

    x=distance*(cos(angle))
    y=distance*(sin(angle))

    is a more direct route and you shouldn't have problems with negatives :)

    http://gamesalad.com/forums/topic.php?id=20867

    Thanks! I will give it a try.
    I didn't think of the problem like you did -- but what you have makes good sense. That is -- just use the equations for orbiting. Except make the orbit distance "0".

    Our equations are almost equivalent. Except your equations omit the -atan(self.offsetX/self.offsetY) part at the end. If that's not needed, and if it fixes the 'negative' issue then I'm all for it!

    Oh -- and it looks we have the sin and cos functions reversed.

    I will give it a try and see how well this works. (I really hope it does since it will simplify things.)

    Thanks again.

    RThurman
  • ctceismcctceismc PRO Posts: 36
    What exactly is distance in the new solution? Distance from what to what?
Sign In or Register to comment.