Rotating an Actor Question...

richcoyrichcoy Member Posts: 211
edited March 2012 in Working with GS (Mac)
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

Best Answer

  • RThurmanRThurman Posts: 2,881
    edited March 2012 Accepted Answer
    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

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited March 2012
    Off the top of my head it would go something like this --

    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
  • richcoyrichcoy Member Posts: 211
    That works great! Thanks. If I have concentric circles with this code is there a way to make only the circle I'm over with my finger turn? Right now if I'm over the middle circle both the inner and the outer circle turn.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    1) Use "touch pressed" instead of "mouse down" in the rule (for booth actors).

    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
  • richcoyrichcoy Member Posts: 211
    Perfect, thanks again. I was thinking through trying your step #2 above just before I read your post. Looks like I may be learning some of this stuff after all. :)

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Glad its working!

    RThurman
  • richcoyrichcoy Member Posts: 211
    The outter rings do lock but they jump to the new angle first. And now that I put some text on the rings I notice that they are jumping to the new angle before rotating with the finger.

    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.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited March 2012
    Yes -- it is because the constrain behavior in the outer circle is firing too fast. You can slow it down by using a timer.

    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
  • richcoyrichcoy Member Posts: 211
    Hmm, still not working. I triple checked my code to yours but the rings are still jumping to the new angle. If I press on the right side of the ring it's almost upright, If I then press on the left side of the ring it jumps to upside down before it follows the arc of the finger. Wish I had a way to show you. :\
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Here is an example:
    http://www.mediafire.com/download.php?o25m5ht0od5tqm2

    Hope it helps!
    RThurman
  • richcoyrichcoy Member Posts: 211
    Yeah, your file has the same issue as mine. If you put a display text behavior on the blocks you'll see that the overlapping issue works great but the blocks jump to the angle before following the arc of the cursor. If you click on the left side of the block it jumps to being upside down then starts following the finger. I think this will take some sorta math with maybe a game attribute that stores the rings current angle. That's beyond my abilities however.
  • richcoyrichcoy Member Posts: 211
    Perfect, Thanks so much. You must be able to make some rockin' games if you can figure weird things like this out!

    Cheers,

    Rich
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    No -- no rockin' games. But I can sure make actors rotate!

    Glad it helped!

    RThurman
  • fishZombiefishZombie Member, PRO Posts: 46
    Speaking of rotations... You seem to be the master. I have an issue of my own. I am just trying to figure out is an object has rotated right or left from it's last known point.
    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 B) which direction. and when it goes right from 2 to 340, that always throws off my math.
  • fishZombiefishZombie Member, PRO Posts: 46
    another question.... How do I get my character (non player) to rotate correctly? If I give him a command to rotate 90, it's fine. He rotates left. BUT... if I give him a command to rotate 300, he ALSO rotates left. He looks like a receiver rolling away from a tackle. I am asking him to face the same direction the hero faces, when the hero gets in range using an Interpolate command. No pop.
  • glyniusglynius Member Posts: 231
    That's cool, i was looking for this for ages....Thanks!!!
    I am trying to figure out how to achieve the same for scaling...any ideas?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @glynius -- I'd recommend starting a new thread with a title that makes sense for your question. (It does not seem to be about rotating an actor.)

    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.
  • glyniusglynius Member Posts: 231
    @glynius -- I'd recommend starting a new thread with a title that makes sense for your question. (It does not seem to be about rotating an actor.)

    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.
    Yeap, sorry, i will make a new thread.
Sign In or Register to comment.