Drag and rotate

wolala123wolala123 Member Posts: 249
edited September 2013 in Working with GS (Mac)
How do the actor can be drag and also can be rotate?thx

Comments

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    As in rotate towards the direction you're dragging too?

    If so, take a look at the vectorToAngle function, that may give you what you need.
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    That being said vectorToAngle rotates to an x and y position supplied in the parameters but if you're dragging it then it's x and y position would be the mouse pointer which would be close to the centre of the actor
  • wolala123wolala123 Member Posts: 249
    i want something like bubble ball game .
  • wolala123wolala123 Member Posts: 249
    That being said vectorToAngle rotates to an x and y position supplied in the parameters but if you're dragging it then it's x and y position would be the mouse pointer which would be close to the centre of the actor
    i have done my drag but come to the rotate, it cant rotate well, it just moving

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    I don't know what bubble ball game is but I'm guessing you want it to rotate towards the direction you're dragging. Is that right?
  • wolala123wolala123 Member Posts: 249
    ya..how to solve it?
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    I'll see if I can throw together something in GameSalad later tonight when I'm home from work.
  • wolala123wolala123 Member Posts: 249
    edited September 2013
    @KevinCross..k...thx.. :)>-
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    This is what I'd probably try if you want to try it yourself before then

    When you start to drag your character (not while you're dragging), store it's start position in two game attributes i.e. game.startDragX and game.startDragY

    While dragging it constrain the actor angle to vectorToAngle(game.startDragX, game.startDragY) - 180

    What this should do (without the -180) is rotate the actor to look towards the start drag point, and the -180 part should flip the angle to look away from the start point.
  • BoomshackBarryBoomshackBarry Member Posts: 712
    I'll see if I can throw together something in GameSalad later tonight when I'm home from work.
    So I'm not the only one who's killing time on the forums when I should be working ;)
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    @BoomhsackBarry nope. I can't actually remember the last time I did any real work at work :)
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited September 2013
    Although my vectorToAngle example was incorrect above I was on the right tracks. Here's the file I promised

    I set it so that it updates the previous x and y position every second, while it's being dragged. You don't need to do this, you could just set the previous x and y postion with the actors position when it's stationary and not being dragged/touched.

    If you find the rotation a little snappy at times then throw in a interpolate to smoothen the rotation.
  • wolala123wolala123 Member Posts: 249
    Although my vectorToAngle example was incorrect above I was on the right tracks. Here's the file I promised

    I set it so that it updates the previous x and y position every second, while it's being dragged. You don't need to do this, you could just set the previous x and y postion with the actors position when it's stationary and not being dragged/touched.

    If you find the rotation a little snappy at times then throw in a interpolate to smoothen the rotation.
    thx....what if i want drag first, then rotate ?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    I think in the bubble ball game, the objects are dragged into place. Then you tap right or left to rotate the objects.

    If this is what you are trying to achieve, you could check for mousedowns and then check to see if the mouse is left or right of the object. If it is on the left side of the scene, then rotate counterclockwise. If the mouse is on the right side, then it rotates clockwise.
  • wolala123wolala123 Member Posts: 249
    I think in the bubble ball game, the objects are dragged into place. Then you tap right or left to rotate the objects.

    If this is what you are trying to achieve, you could check for mousedowns and then check to see if the mouse is left or right of the object. If it is on the left side of the scene, then rotate counterclockwise. If the mouse is on the right side, then it rotates clockwise.
    how to determine left or right?can you do a demo to me?thx
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    Try this:

    When the mouse is down
    -- When game.mouse.position.X < game.screen.size.width/2
    ----rotate counterclockwise
    --otherwise
    ----rotate clockwise
  • wolala123wolala123 Member Posts: 249
    @RThurman...thx...it work well...but i have this two or more same object ,how to separate them, don't want them move at the same time?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    Great question.

    If you can tell us how you want to solve this, I am sure someone on the forum will be able to give you hints on how to do it.
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    Oh... so you didn't want it to rotate in the direction it's dragged then!

    To only rotate one at a time, and only the one you last dragged, try the following:

    • add two integer game attributes called bubbleCounter, and lastBubbleDragged
    • add an integer attribute to to the actor called bubbleID
    • at the top of the bubble actor add a change attribute to increase the game.bubbleCounter by one.
    • underneath that add a change attribute to set the self.bubbleID with game.bubbleCounter.
    • in the drag rule on the actor add a change attrubute to set game.lastBubbleDragged with self.bubbleID
    • on the rule where you're rotating the actor add "if self.bubbleID = game.lastBubbleDragged".

  • wolala123wolala123 Member Posts: 249
    Oh... so you didn't want it to rotate in the direction it's dragged then!

    To only rotate one at a time, and only the one you last dragged, try the following:

    • add two integer game attributes called bubbleCounter, and lastBubbleDragged
    • add an integer attribute to to the actor called bubbleID
    • at the top of the bubble actor add a change attribute to increase the game.bubbleCounter by one.
    • underneath that add a change attribute to set the self.bubbleID with game.bubbleCounter.
    • in the drag rule on the actor add a change attrubute to set game.lastBubbleDragged with self.bubbleID
    • on the rule where you're rotating the actor add "if self.bubbleID = game.lastBubbleDragged".

    Oh yeah, man..it works well and it is i want...thx a lot...=)
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    You're welcome :)
Sign In or Register to comment.