rotating by multitouch
Hunnenkoenig
Member Posts: 1,173
I believe, Tshirt or Firemapple linked somewhere a demo with something like that, but I can't find it.
I want to rotate an image by multitouch, but I can't figure out, how to do it the best way.
If I use angletovector and change the rotate attribute by this number, it works somehow, but it is not good.
Any advice?
I want to rotate an image by multitouch, but I can't figure out, how to do it the best way.
If I use angletovector and change the rotate attribute by this number, it works somehow, but it is not good.
Any advice?
Comments
http://gamesalad.com/forums/topic.php?id=502
CodeMonkey has a demo here:
http://gamesalad.com/game/play/22929
http://gamesalad.com/forums/topic.php?id=502
And while we're at it, where is the origin in GS? The center of the display, or one of the corners? The Expression Editor Reference says vectorToAngle uses the "origin" but doesn't clarify where exactly the origin is.
The origin is in the lower left corner of the screen, or "camera". If the camera moves, an Actor instance, (like the Scene controller you just made) has access to Camera.Origin.X and Camera.Origin.Y
@Hunn: yes, you will need VectorToAngle to give you the angle between the two touches. When you first touch the actor, capture those touches' angle by using VectorToAngle. That will be the starting point, or zero point. Then, constrain the rotation of the actor based on the difference between the current vectorToAngle minus the Original VectorToAngle.
So:
Change Attribute: originalTouchAngle To: vectorToAngle(touch1.X-touch2.X,touch1.Y-touch2.Y)
Constrain Attribute. self.rotation to vectorToAngle(touch1.X-touch2.X,touch1.Y-touch2.Y)-originalTouchAngle
That's just off the top of my head, so it probably won't work!
But I think that's sort of the basic idea...
I gave up on it and I made just a switcher, where if it is on, a touch will just rotate the actor counter clockwise.
Maybe later I will mess around with this again.
make 2 attributes
game.touchy
game.releasey
"
You enjoy naming attributes, don't you!
Create an invisible actor with rule:
when touch is pressed
constrain self.positionY to touchY
constrain self.positionX to touchX
constrain game.spinY to self.positionY
constrain game.spinX to self.positionX
In the spinning objecting:
When touch is pressed and inside
constrain self.rotation to VectorToAngle(self.positionX-game.spinX, self.position.Y-game.spinY)
Use this example.
To explain another way: using the above, the actor when clicked "jumps" (rotates) to the current touch position. I'm trying to find a way to take into account the actors current rotation so it doesn't jump to a new rotation upon the initial touch/click.
I tried storing the current rotation in an attribute and using abs(current angle - new angle) and abs(new angle - current angle) but failed miserably -- I'm doing something wrong and am not sure how to account for the 359.99 limit on rotation.
Thanks for any suggestions you can offer.
When I tried to store the angle, so it doesn't jumb back to your touch.
If you get it work, please post a demo :-)
On the initial click/touch, don't rotate the actor, store the offset of the vectorToAngle() of the click minus the current Rotation of the actor in an attribute (I used rotationOffset).
Pseudo-code:
RULE
if allowRotation = true
CHANGE ATTRIBUTE
(self.rotationOffset = vectorToAngle(actor.position.X-game.Mouse.Position.x,actor.Position.Y-game.Position.Y))-actor.Rotation
[ Then in the same rule, constrain the rotation of the actor to the current vectorToAngle() minus the rotationOffset ]
CONSTRAIN ATTRIBUTE
actor.Rotation to vectorToAngle(actor.position.X-game.Mouse.Position.x,actor.Position.Y-game.Position.Y))-self.rotationOffset
Over here, this allows rotation of an actor using its current rotation, so there's no initial "jump" when clicking. Need to try this on an actual device, but it works fine in Creator.