Touch & Drag to Aim, Release to Fire?

Get help using Construct 2

Post » Sun Mar 03, 2013 6:26 pm

First things first, want to say thank you to everyone on the forum. I'm brand new to C2 and everyone has been incredibly helpful. Really appreciate it.

I'm looking to create an action for a touch based game. The idea is if you touch the sprite and drag your finger away from it, the ability to aim will be enabled in the opposite direction. A similar idea is found in the game Gersundheit. The plan is to use it as a sort of whip to collect tokens.

I have spent the last week trying different combinations and searching the forum and can't seem to find any solution. Could anyone point me in the right direction?

Thanks!
B
17
S
8
G
1
Posts: 25
Reputation: 2,649

Post » Sun Mar 03, 2013 6:34 pm

I would make 4 variables.
StartX
StartY
EndX
EndY

On touch begin, I would set StartX and StartY as Touch.X and Touch.Y.
On touch end, I would set EndX and EndY as Touch.X and Touch.Y once again.

What I'd have had there would be the start and end of my drag. From there I could use the angle(StartX,StartY,EndX,EndY) to find the angle the player has drawn. From there, I can launch the projectile to the Angle I just calculated. If it's inverse or anything like that, you could just use -(angle(StartX,StartY,EndX,EndY)) or something mathematical along that lines.

Hope this helps!
B
36
S
10
G
6
Posts: 948
Reputation: 11,101

Post » Sun Mar 03, 2013 6:45 pm

@Rory, thanks for the quick response! I'll give it a test right now. Really appreciate it.
B
17
S
8
G
1
Posts: 25
Reputation: 2,649

Post » Sun Mar 03, 2013 7:51 pm

Have a look at the "Physics Catapult" template.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sun Mar 03, 2013 9:57 pm

YOu should also base your velocity on some type of multiplier of the distance the item has been pulled from the starting position.
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,428

Post » Mon Mar 04, 2013 5:05 am

Yeap @BluePhaze is right, you can calculate that with distance(StartX,StartY,EndX,End.Y) :)
B
36
S
10
G
6
Posts: 948
Reputation: 11,101

Post » Mon Mar 04, 2013 6:36 pm

Really appreciate all the tips!

I worked on it last night and got pretty far with a combination of the suggestions you all gave. I can aim by touch and drag on the player sprite and fire when the touch/dragged is removed.

The problem I am now running into is with the navigation. I need to be able to use pathfinding to find a path to a touch, however when I do so, the player sprite fires.

Can't seem to find a way to separate the two events without getting one (or the other) to stop functioning.

Here is my first capx (it's rough): https://docs.google.com/file/d/0BwBgS0CgFcUdMXJ6WjBXRVhxSWs/edit?usp=sharingBillionYrBunker2013-03-04 18:38:26
B
17
S
8
G
1
Posts: 25
Reputation: 2,649

Post » Mon Mar 04, 2013 6:39 pm

Again, really, really appreciate all the help!

My mind has been blown by Construct 2.
B
17
S
8
G
1
Posts: 25
Reputation: 2,649

Post » Wed Mar 06, 2013 3:22 am

use a variable set the current state, have one for firing and one for target location. activate/deactivate your events based on the variable
B
49
S
11
G
10
Posts: 1,833
Reputation: 14,428

Post » Thu Mar 07, 2013 3:02 am

Good call... I'll give it a test tomorrow. Thanks!
B
17
S
8
G
1
Posts: 25
Reputation: 2,649

Next

Return to How do I....?

Who is online

Users browsing this forum: Colorfish, MarkThomas and 32 guests