Moving the Character by Mouse/touch Dragging

  • Hello,

    There are some games where, when you press and hold down the left mouse button and drag it across the level or screen, the player character follows it. Same occurs on mobile: you drag with your finger and the player character follows wherever your finger goes.

    Does anyone know how to do this?

    I can get the player character to move to mouse.x and mouse.y but it only moves it instantaneously.

  • There are many ways to do this..

    One important question is ofcourse, what kind of movement do you want?

    platform, 8-ways or something totally different?

    You shouldn't set the player position, but the direction of the movement of the player towards mouse.x, mouse.y

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Right now, I have multiple movements: 8 direction (keyboard), pathfinding (mouse and touch).

  • I'll give you a for instance, using bullet-behavior

    set bullet angle towards mouse.x,mouse.y (if you are using touch, remember that touch.x and touch.y only have values while touching, so in that case it's easier to work with a sprite set to touch.x, touch.y (only while touching) and set angle towards that)

    set bullet speed to whatever..

  • Thank you, I was able to do it. Unfortunately, because I have multiple ways to move, it messes up. But alone, the mouse drag works.

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