Dragging rotation

0 favourites
  • 14 posts
  • Hi again..

    I have an object, that is setting its angle to: is in touch-->touch.x, touch.y .

    It works fine, but when I lift my finger and place it again on screen, the object angle resets as it should hold the angle that it had when the finger stopped touching..

    I think I have seen a forum post about something similar, but of course I'm not able to find it as I need it..

    Help appreciated!!


  • Hey Chef

    Here is a quick and simple example of how to achieve what you want (I'm sure there are more elegant solutions).


    To explain,

    I created a "Moved" variable and made it that ONLY when the variable is less than 2, move the ball to the touch angle. As the ball gets moved the variable also switches to 1.

    As you see the next event registers when the variable is 1 and touch is inverted (I.E not touching) and the action sets "Moved" to 2 so that it wont be able to move again.

  • Hi there,

    GenkiGenga, I was very interested in your example and downloaded it. I made few changes because the button was turning wherever the touch accured on the screen. So I make it happen only when the button is touched. I also made some changes with the variable because once turned, the button couldn't be moved again.

    But I still have one problem : when the button is touched, it immediately goes into one direction before being able to rotate as wished.

    Do you know a way to correct that ?

    Thanks !


  • Hey Laurent,


    The problem was because the line you drew is actually running on the left hand side of the circle (objects face the right in the editor). I've rotated your circle (in the edit animations window) so that the line now faces the right so it lines up wherever the mouse is clicked. Is that what you meant?

  • GenkiGenga, looks great now, thanks !

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • No worries ;)

  • Hey, thanks for the posts! But this still doesn't fix what I was after.. Maybe I wasn't clear enough.

    I was looking for a way to "store" the angle of the object, so that when you want to rotate it again, it would move from the angle it was set when the touch ended.. Now as you can see from these great examples, it still jumps to the angle of touch before it starts to rotate.

    Is this a case for local variables..? I'm still a "semi-noob" to construct and really haven't looked into them yet.

  • Oh you wanted it to rotate to where the mouse is?

    Try this link again.


    It now rotates to where the mouse is when touching, if you only want to click once then you can create a marker sprite where you click the mouse and then set the angle to that instead of Touch.X, Touch.Y

  • Umm...Well..No.. :)

    The first link I posted is rotating the object how I wanted.

    I'll try to explain once more and if I'm not clear enough now, i'll lock myself up for a month and challenge C2 for a last-man-standing duel!

    In the capx I posted:

    The object is facing 0-degrees, as a default by C2.

    As I touch/hold mouse, the object angle follows touch/mouse..

    It's all good if I put my finger/mouse back to the exact same angle where it was when I stopped touching and then drag. But if I start to drag from, let's say the start of layout and the object is still 0-degrees. I place my finger to the left side of the screen, the object angle snaps to touch.x, touch.y and then it follows the touch..This is not what I'm looking for..

    I would like to see the object rotate from the angle it was left after touch or start of layout, no matter where I place my finger on the screen.

    **crossing fingers**

    <img src="smileys/smiley2.gif" border="0" align="middle" />

  • Did you download the example in the last post? Its the same link but I had updated it.

    What you should be seeing is the ball rotating to where you hold the mouse, click and hold somewhere else and it rotates from its end position to your new angle.

    In your example you have the object angle set to your mouse, that's why it snaps to the location and follows the mouse so crisply. If my example is rotating too slowly then change the degree value from 1 to 3 etc and it will speed up to the same effect.

  • Yes I tried it but I would like the ball angle to actually follow the touch element and not to snap to the new angle or rotate to it.

    This is a good way to do it but just not THE thing I'm after. I really think I saw an earlier post saying something about storing the object angle in a variable or something and then recalling it on the next touch.. Maybe it was a dream, it seems..

  • Hmm, well I am confused. :)

    Sorry I couldn't help Chef. I'm sure you will get what you want with enough mucking around.

  • Thanks anyways!! Yeah, I'm sure it can be done.. When it's ready, I'll post it here just to show what I mean.

  • Capx Link

    After a good night sleep, I started fiddling with C2 and found out it was an easy fix to do. <img src="smileys/smiley9.gif" border="0" align="middle"> It's not pretty, but as said, it does the thing!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)