How do I slide movement like in Pudding Monsters

Get help using Construct 2

Post » Fri Apr 25, 2014 9:06 pm

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.
B
8
S
4
Posts: 120
Reputation: 1,266

Post » Fri Apr 25, 2014 11:32 pm

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.
You do not have the required permissions to view the files attached to this post.
B
38
S
12
G
11
Posts: 331
Reputation: 7,712

Post » Sat Apr 26, 2014 6:11 pm

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!
You do not have the required permissions to view the files attached to this post.
B
8
S
4
Posts: 120
Reputation: 1,266

Post » Sat Apr 26, 2014 6:27 pm

Just sent you a pm
B
38
S
12
G
11
Posts: 331
Reputation: 7,712

Post » Sat Apr 26, 2014 6:35 pm

Sorry can't reply, I need 500 rep :(
B
8
S
4
Posts: 120
Reputation: 1,266

Post » Sat Apr 26, 2014 6:47 pm

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.
B
38
S
12
G
11
Posts: 331
Reputation: 7,712

Post » Sat Apr 26, 2014 6:56 pm

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: https://www.youtube.com/watch?v=IoJCCHv-gf4 this is the exact movement I want to achieve
B
8
S
4
Posts: 120
Reputation: 1,266

Post » Sat Apr 26, 2014 7:59 pm

Here is an updated file with the motion type.
You do not have the required permissions to view the files attached to this post.
B
38
S
12
G
11
Posts: 331
Reputation: 7,712

Post » Sun Apr 27, 2014 9:30 pm

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.
You do not have the required permissions to view the files attached to this post.
B
8
S
4
Posts: 120
Reputation: 1,266

Post » Mon Apr 28, 2014 1:34 am

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.
You do not have the required permissions to view the files attached to this post.
B
38
S
12
G
11
Posts: 331
Reputation: 7,712


Return to How do I....?

Who is online

Users browsing this forum: Held, NN81, TsubaRu and 8 guests