How do I slide movement like in Pudding Monsters

0 favourites
  • 10 posts
From the Asset Store
3 different games for kids, easy to edit, mobile ready
  • Hey there, I'm trying to figure out a way to get slide movement with the touch object.

    Basically I want my sprite to move in the direction i'm sliding my finger in. so for instance when I have my finger on the sprite, it does nothing. But when I slide over it to the right it moves to the right and so on.

    I got a system working so far, where I just have 4 invisible boxes around the sprite, that are pinned to the sprite. Whenever my finger touches one of those boxes it moves in that direction.

    Is there a quicker/compacter way to do this? Because now I have 4 different objects just for movement and I'm guessing this isn't really how it's supposed to be done.

  • I am in an example mood today, so I threw together a quick capx for you.

    It can be done easier simply by getting the input device position - the point of reference position.

    In the capx file, I created a system similar to many of the mobile games out now where, when the left mouse button is held down, a circle appears on the screen representing the players joystick centered at the mouse location. When you move the mouse to one of the sides of the circle, the blue rectangle begins to move in the same direction. The farther from the center of the red circle the mouse is, the faster the box will move. When you let go of the mouse button, the joystick disappears.

    For your example, instead of having the joystick, you would use the position of the character compared to the location of the players finger. I hope this gets you the information you need and good luck with your project.

  • Hey thanks a lot that example! really did help me get a new base for the movement.

    I tweaked it a little bit to try and fill my needs but it's not really working out for me yet.

    As you can see in the attached capx, I added some walls that stop the Sprite, and made it so the sprite keeps on moving till it's stopped by walls.

    Thing is, I can point anywhere on the screen and the Sprite will move towards there. I was thinking about a variable to check if the player had contact with the Sprite first and then move. But when I try to add one, there's suddenly no movement at all. I also wanted the Sprite to be restricted to 4 directional movement only and be able to move only when it's already stopped. Still trying to figure out this all, but it someone could help that'd be awesome!

  • Just sent you a pm

  • Sorry can't reply, I need 500 rep

  • Ok, well then we'll do it here.

    First: Your setup has movement happening after the player lets go. I didn't understand this from your first message. Is this the desired effect?

    Second: As it is set up, when you click, the movement is set to 0 (first event on touch sets movement to 0) and then reset in the new direction when you let go. You said you wanted the movement to only work if the sprite isn't moving.

    Finally: When you say "a variable to see if the player has contact with the sprite first..." it sounds like you want a slingshot type effect. Click and drag off of the sprite to create force. Then when the player lets go the object flies off in that direction. Is this correct?

    I have some time today, so if you get back to me quickly, I can update my example to be more what you are looking for.

  • You were right about the (reversed) slingshot effect, I've never looked at it that way. That alone already helps me alot since there are tons of tutorials that explain how that works!

    And yes, I want the player to only be able to use the "slingshot" when the Sprite itself isn't moving. So you'd have to wait till it bumped into a wall untill you can sling it again.

    I'll go ahead and read some of the slingshot tutorials and see if I can figure some things out on my own. It'd be awesome if you could update your capx, so I can compare mine to yours and see what I'm doing wrong and right.

    Thanks!

    EDIT:

    Subscribe to Construct videos now

    this is the exact movement I want to achieve

  • Here is an updated file with the motion type.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks, this is hard.

    I'm trying to figure out what every variable does.

    MoveXY decides wether the sprite moves and how fast right?

    I tried to add a variable to make disable changing the movement of the Sprite, while it's already moving., because when you click anywhere on the screen the Sprite still moves, and if you click somewhere and quickly somewhere else it changes direction.

    Thanks for the help anyway, but I guess it's better for me if I keep it to stuff I understand haha. So I guess I'm going back to the 4 invisible boxes around the sprite. to get the disired effect I linked in the video earlier.

  • Instead of adding another variable, you can just check the MoveXY variables to see if they are = to 0 in event 3. I have added that to the attached version.

    I am guessing it is events 4 and 7 that are the ones you are having trouble with. Simply put, these 2 events find which direction the player is dragging. This set of events makes sure the sprite only travels vertically or horizontally, not both.

    The abs function returns the absolute value so if the amount from the subtraction is negative, abs returns the positive equivalent (in other words abs(-5)=5 and abs(5)=5).

    Event 4 triggers when the distance between Touch.X and Sprite.X is greater or equal to the distance between Touch.Y and Sprite.Y.

    Event 7 triggers when the Y distance is greater (basically any time event 4 doesn't trigger).

    <Edit> I just realized, I was setting 2 variables, InitialX and InitialY, but never using them. These 2 variables were meant to make sure the player touched the sprite before allowing movement to happen. That is why you could touch anywhere and the sprite would move. Sorry about that. It is fixed.

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