How do I make Touch movement on Mobile? (SOLVED)

0 favourites
  • 8 posts
From the Asset Store
Run and Jump in 3 Dimensions! Take your platformer to the next level!
  • Greetings, this has probably been asked a lot before, but I haven't find any satisfactory answer to my problem.

    Basically, I have the current code for Touch movement in my game:

    But when played on phone, the users fingers will cover up the character entirely, making it unpratical for proper enjoyment. I wish to make a more drag and drop like movement, where as the player drags across the screen, the sprite will immitate the same movement on it's own space, without necessarily following the touch position, like it is in the image.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here is the easiest way:

    On Touch start 
    	Set dx to (Touch.x-Sprite.x)
    	Set dy to (Touch.y-Sprite.y)
    
    Is in Touch
    	Sprite set position to (Touch.x-dx, Touch.y-dy)
    
  • Here is the easiest way:

    > On Touch start 
    	Set dx to (Touch.x-Sprite.x)
    	Set dy to (Touch.y-Sprite.y)
    
    Is in Touch
    	Sprite set position to (Touch.x-dx, Touch.y-dy)
    

    Is dx meant to be a global variable? If so, it doesn't quite work, the sprite just teleport to a place close to the touch, so it's very inpractical. However, the "Is in touch" part is very nice, it's the kind of touch-slide I want, but it's not practical with this teleportation bug.

  • dx and dy can be instance variables on the sprite, or global variables. I tested this code and it definitely works.

  • dx and dy can be instance variables on the sprite, or global variables. I tested this code and it definitely works.

    This version of the code you showed me does have some issues with the sprite teleporting before moving, however after tweaking a bit overnight, I manage to make it work like a real mobile game.

    Regardless, thank you for showing me this option, otherwise I wouldn't be able to make this one!

  • I don't understand why you had to add those conditions. I don't think they change anything, because at least one of them is always true, so there is no point in them.

  • I don't understand why you had to add those conditions. I don't think they change anything, because at least one of them is always true, so there is no point in them.

    Like I said, the code you sent me didn't work 100% like I wanted, it showed some issues so I changed it up to that, which functioned exactly to what I was needing. And yes, these paramenters do matter because they only worked after I have putted them in the code.

  • Could you share your project file? I am still quite sure that these conditions are useless and not required here, but maybe I can find the real reason why the code doesn't work without them.

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