How do I change direction with tap?

Just started using Construct 2? Post your questions here

Post » Wed Sep 14, 2016 5:10 am

Hello. My first post! I am going through tutorials and learning the basics of C2 at this point.

I want to create a simple player control where each tap reverses the player movement.

Game Start: Player Idle
First Tap: Player moves right
Second Tap: Player moves left
Third Tap: Player moves right

and so on, while continuously facing forward. Can anyone point to the tutorial or methods to do this?
I am trying to detect which way the Player is moving and accelerating towards Player.X + or - 2000, but not doing anything correctly, not to mention this probably requires 2 taps to reverse movement.

(Pic of my failed control attempt)
https://drive.google.com/open?id=0ByWkQ ... 2Y1UHRBdkE

Thank you in advance.
B
5
S
2
G
1
Posts: 4
Reputation: 935

Post » Wed Sep 14, 2016 5:28 am

First off, welcome to the wonderful world of C2!

You could put a boolean instance variable on the player to keep up with which way it's going. call it "isleft" (or whatever you like).

on touch >>>
(subevent)-If player isleft = "true" >>> set isleft false AND start moving player right
----------------Else >>> set isleft true and start moving player left.


EDIT: oh, actually that won't work with the way you're doing the movement...

let me rewrite:
on touch >>>
(subevent)-If player isleft = "true" >>> set isleft false
----------------Else >>> set isleft true

(new event)
if player isleft=true >>> move left
else >>> move right.
B
86
S
43
G
71
Posts: 601
Reputation: 43,619

Post » Wed Sep 14, 2016 5:59 am

Thanks for the welcome and the reply spacedoubt!
Will give this method a try!
B
5
S
2
G
1
Posts: 4
Reputation: 935

Post » Wed Sep 14, 2016 7:07 am

Thanks to your advice I was able to move left and right with a tap!
It is working splendidly.

However, if I make a quick successive taps, it will only register the turn once.
(if I double tap, the two actions should cancel out so the player should zigzag a bit and keep going. However currently it will only recognize one tap, and will only change direction once)

How would I be able to fix this issue?

Here is the Capx file just incase.
https://drive.google.com/open?id=0ByWkQ ... WprRmdIZkU

Here is the Event page screenshot
https://drive.google.com/open?id=0ByWkQ ... m1FT3Y5VTA
B
5
S
2
G
1
Posts: 4
Reputation: 935

Post » Wed Sep 14, 2016 7:19 am

Fixed myself!

I changed input event from "on tap" to "any touch start" and its working now!
B
5
S
2
G
1
Posts: 4
Reputation: 935

Post » Wed Sep 14, 2016 7:23 am

Sweet! Yeah, 'on tap' triggers on a quick touch and release... It also makes me want a beer...
B
86
S
43
G
71
Posts: 601
Reputation: 43,619


Return to Beginner's Questions

Who is online

Users browsing this forum: brunopalermo, JackTYGA and 4 guests