Free Yourselves From The Tyranny of Center Only Rotations!
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?!?!
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?!?!
Comments
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!
That's some great stuff right there! Thanks for sharing, I'm sure it'll be useful!
QS
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?
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
RThurman
@RThurman - Very nice. Good to see we have a new math wiz we can lean on
cheers kipper
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
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!
RThurman
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
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
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.
(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
_______________________________________________________________________
Here’s Gameplay Video of Bouncing Birds!
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?
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.
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.
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
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?
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.
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
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.
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
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