follow touch

Get help using Construct 2

Post » Wed Aug 07, 2013 9:11 pm

I would like my player sprite to go to the finger on touch so that it can be moved without buttons. So wherever the finger touches, the sprite will "walk" to it.

Here is my code. Any suggestions on why this is not working correctly?

B
18
S
2
Posts: 61
Reputation: 902

Post » Wed Aug 07, 2013 9:31 pm

just do this instead:

On touch
--> set player.x = touch.x
--> set player.y = touch.y
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Wed Aug 07, 2013 9:47 pm

Thanks very much! That works well she goes all around and follows my finger but now there are 2 new problems...

She goes through solid objects & she flips and flops all around. She looks like a person so sometimes she flips to stand on her head or spins and it looks crazy. I know that's the angle, etc and can probably eventually fix it but what about stopping her from following my finger through solids?

She is set to "collisions enabled" and her bullet set to bounce off solids.
B
18
S
2
Posts: 61
Reputation: 902

Post » Wed Aug 07, 2013 9:53 pm

Her angle stays straight with the keyboard controls. I hope by fixing her to stay straight with touch it doesn't ruin that?
B
18
S
2
Posts: 61
Reputation: 902

Post » Wed Aug 07, 2013 10:03 pm

I made a small maze example at some point using the line-of-sight behavior. That could be used.

.capx

You could set the angle to 0 when you set the x and y as well.

argh.. wth... like this    .capx cvp2013-08-07 22:05:50
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Wed Aug 07, 2013 10:36 pm

Wow the lab3 sample helped me so much!! Now she moves perfectly :) Now just to figure out how to get her to know which way she's going so to set her animation. Thanks so much for your help.
B
18
S
2
Posts: 61
Reputation: 902

Post » Wed Aug 07, 2013 10:54 pm

A lab4 for you then

The distance thing is to stop it from doing a "jitter"

.capx

Try to disable it and you will see the difference.
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Thu Aug 08, 2013 2:43 am

Okay I have modified the lab4 code a little bit to fit my purpose. My sprite is transparent "Player" with pin for "Player Animations". She is still not flipping to face her direction so I'm not sure what I've done wrong @cvp? Here is my new code now

B
18
S
2
Posts: 61
Reputation: 902

Post » Thu Aug 08, 2013 7:13 am

You need to remove the two event actions you have in the "is in touch"
In lab 4 they were moved to the bottom. (you can see you have them twice now)



The reason why yours will not change face direction is because as your code looks now you are setting the position of the player before your check the distance. So the distance will always be 0.
Thats why the Set position and angle was but down at the end.cvp2013-08-08 07:15:43
B
20
S
6
G
4
Posts: 347
Reputation: 4,451

Post » Thu Aug 08, 2013 7:36 pm

Ah of course!! You've taught me a lot thanks so much again. I know this thread will come in handy for others too.
B
18
S
2
Posts: 61
Reputation: 902

Next

Return to How do I....?

Who is online

Users browsing this forum: blissfulwizard, DevinMurray, newt and 14 guests