Touch drag and drop labyrinth

Get help using Construct 2

Post » Thu Jul 11, 2013 11:31 pm

Hi

I am trying to develop a labyrinth game for touch devices. I have searched they forum alot and havent been able to find the help i am looking for.

I found a great example by @Yann where a circle limits anothers circles movement.
That is the closest i have found. (Yann's example)

I would like to be able to drag a sprite through the labyrinth. i have made a small image to help illustrate.




The problem is that i cant get my head around how to block the sprite from stopping at the wall, but still going along the wall as the circle does in yann's example.

And make sure the sprite does not "jump" over the wall.

Hope you can help me.
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Fri Jul 12, 2013 12:24 am

I made a game like this recently.

Green Labyrinth
Green Labyrinth Classic

What I did was add the bullet behavior to the object, and sent the angle toward the touch x and y. It worked fairly well. Make sure that bounce off of solid is enabled though.yogert962013-07-12 00:25:30
B
11
S
2
G
3
Posts: 50
Reputation: 2,765

Post » Fri Jul 12, 2013 1:19 pm

Thanks for the example yogert96

I hadnt really though about using the bullet behavior for this.

I made a small example.

It works... ok i would say. it still does not feel like i am dragging the object. it more the object moving towards the touch.

So i would still be interested if there was another example which would be more drag&drop ish... if you know what i mean.

Another thing. when i use the bullet behavior it seems to bounce alot on the walls, which makes it flikker alot.

.capx
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Fri Jul 12, 2013 5:15 pm

If you change the Speed Event to the Angle Event your sprite will move better.

Something like this:

Is In Touch=>|Set Speed to=> <<Something>>
                      |PlayerObj=>Set angle toward X= round(lerp(self.X, Target.X, 2))                                       
                                                                     Y= round(lerp(self.Y, Target.Y, 2))

You can add dt to the thir value as you did.

If you add Solid behavior to your moving Object and add Solid to the collison object for the walls it should collide.
(As long as you enable Bounce off solid on the bullet properties of course.)

This movement works for me.
And, by the way, if you find a better movement method tell me :D
B
31
S
4
G
4
Posts: 110
Reputation: 4,593

Post » Fri Jul 12, 2013 6:58 pm

You mean something like this: .cpax ?

you are right the angle change makes movement better. I can still keep the speed lerp as well though.

But it does not fix the "flikker". If you e.g. move the ball to the "Y" shaped corner, you can actually get it to jump the wall because it "flikkers" so much.cvp2013-07-12 18:59:13
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Fri Jul 12, 2013 8:13 pm

In you capx I see the same code you posted in your first capx.

I'm installing Dropbox in this machine since my other blowed up on me.

What i mean is that in X an Y expresions of "Set angle toward" you could put:
X: lerp(Self.X, Touch.X, dt*0.5)
Y: lerp(Self.y, Touch.y, dt*0.5)

Play with dt until you have something less jumpy.

Also you can use this to stop the object at the touch position (your finger or the mouse's cursor):
(As a subevent of "Is in touch")
   System|>Compare two values|>distance(Player.X, Player.Y, Touch.X, Touch.Y)<=10 = Set Bullet speed to 0

Play with that 10 to match your desired offset. It helped me overcome shakiness when the player reach the destination point.

About the sprite trespassing your walls. I don't see it happening in my example.
My only difference is that my wall objects have always the same or more width. And i have "Pixel Rounding" on. But i doubt this cause issues on collisions.
B
31
S
4
G
4
Posts: 110
Reputation: 4,593

Post » Fri Jul 12, 2013 8:19 pm

Sorry, i saved the file in the wrong location :-/ it should show the changes now in the link.

I'll try to play around with what you wrote and see what i come up with.

A second though, just throwing out an idea. What if you were to look at it from the opposite direction. Instead of telling the ball where it cant go, could you limit it to only move on top of sprites or something down that alley.
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Sat Jul 13, 2013 8:43 pm

Love and behold just as you don't know what to do... you stumble upon one of the new features in Construct 2. @Scirra i love you :-)

Try this out for size... Touch labyrinth

Using the new Line-of-sight behavior.

It does exactly what i was looking for.

On a side note. Fun story.. I actually knew about the new line-of-sight behavior, but I didnt think of it.
Until I was trying to get more rep on the website and was going through the manuals to get some more reputation So dont say the badge system aint good for something cvp2013-07-13 20:55:50
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Sun Jul 14, 2013 2:53 am

hey, you're technique is great! i was trying to achieve the exact same thing as you were. i modified it so that it doesn't overlap the walls. is there any way to make the object slide along the walls, instead of freezing when it hits a wall? here's the capx

https://www.dropbox.com/s/25m5ro22cfjydh8/lab2examplemodified.capx
B
6
S
1
Posts: 22
Reputation: 459


Return to How do I....?

Who is online

Users browsing this forum: adamebastin, Bro7hers, plinkie, radbrothers and 8 guests