Rotating an Actor Question...
Hi,
Tried posting this a minute ago and don't see it in the forum, forgive me if this duplicates.
I want an actor to rotate like a combination lock, around it's center, following the finger when touched. I'm having a difficult time figuring out how to accomplish this. Probably over-thinking it. Any tips? Also, how would I get it to start out rotated a random amount each time the scene loads?
Thanks for any tips you can offer.
Rich
Tried posting this a minute ago and don't see it in the forum, forgive me if this duplicates.
I want an actor to rotate like a combination lock, around it's center, following the finger when touched. I'm having a difficult time figuring out how to accomplish this. Probably over-thinking it. Any tips? Also, how would I get it to start out rotated a random amount each time the scene loads?
Thanks for any tips you can offer.
Rich
Best Answer
-
RThurman Posts: 2,881
Oh -- OK it took me a while to realize that you are saying that the circle rotations are now separated OK but that you have noticed a new 'challenge'. That the new thing is that the actors jump or snap to the mouse angle, instead of smoothly following the mouse.
(This often happens. You will also notice a similar 'snap' if you try to drag actors around with the mouse. They will 'snap' the center of the actor to the mouse, unless you do a bit of adjusting.)
Here is how to fix the rotational 'snap'. Before you do anything you need to find the difference between the actor's current rotation and the mouse angle. Then take that into account when determining the angle to rotate. (Ugg... its easier to just show how to do it than to explain it!)
---------
Create an actor attribute (type = real) and name it "offsetAngle" (or whatever you like). Then include the following behaviors:
Rule: When touch is pressed
-- Change Attribute: self.offsetAngle To: vectorToAngle( game.Touches.Touch 1.X - self.Position.X , game.Touches.Touch 1.Y - self.Position.Y )- self.Rotation
-- Constrain Attribute: self.Rotation To: vectorToAngle( game.Touches.Touch 1.X - self.Position.X , game.Touches.Touch 1.Y - self.Position.Y )- self.offsetAngle
That will get rid of the 'snap' you have discovered.
Here is an example:
http://www.mediafire.com/download.php?olkk8a9he8rmom3
Hope that helps!
RThurman
Answers
For random rotation:
change attribute: self.rotation to: random(0,359)
For following a touch:
constrain attribute: self.rotation to: vectorToAngle(game.Touches.Touch1.X - self.position.X, game.Touches.Touch1.Y - self.position.Y)
hope that helps!
RThurman
2) The outer circle should work as expected. But for the inner circle, you may need to set up a game attribute to indicate when it is being pressed. (Then add a condition in the outer circle that tests to see if the inner circle is being pressed.)
Hope that helps!
RThurman
RThurman
It's probably way more complex but is there a way to do this where they don't jump? I'm working on a combination game and the circles changing angles so abruptly would make for a difficult/frustrating playing experience.
I appreciate your help.
Put a timer in the outer circle and set it to 'after 0' seconds. Here is how it would look if you had a game attribute (boolean) called innerPressed:
Rule: When Actor receives event 'touch is pressed'
-- Timer: After 0 seconds
----Rule: When Attribute 'innerPressed' is false
------Constrain Attribute: self.rotation To: vectorToAngle( game.Touches.Touch 1.X - self.Position.X , game.Touches.Touch 1.Y - self.Position.Y )
Hope that helps!
RThurman
http://www.mediafire.com/download.php?o25m5ht0od5tqm2
Hope it helps!
RThurman
Cheers,
Rich
Glad it helped!
RThurman
I am firing rectangles at a wall. When they hit the wall, they stick. I want to know which direction they rotated. When the bullet is spawned it saves an attribute of it's current rotation value. And I know the value after it stops... but... I can not figure a way to just get a value for A) how much it rotated, and
I am trying to figure out how to achieve the same for scaling...any ideas?
Also, when you make the new thread, you might want to add a little more detail. I'm not quite sure what your question is about.