# How do I create a swing in the ball

Get help using Construct 2

### » Wed Feb 04, 2015 6:54 am

Hey,

I am planning to start a football penalty kick game, but not sure how does the swing in the kick works.

When we swipe up - the ball goes towards the goal post

and in the halfway of the swipe if I move my finger towards left - the ball should swing left.

Even if you could show me how it works in capx (just a simple idea) that will help a lot. THANKS
B
7
S
1
Posts: 51
Reputation: 507

### » Wed Feb 04, 2015 12:45 pm

Hi,

see this topic:
scirra.com/forum/behavior-swing_t64261?&hilit=swing

maybe you understand how is working.. : -)

Cheers..
B
67
S
40
G
20
Posts: 251
Reputation: 16,572

### » Wed Feb 04, 2015 1:59 pm

@odiusfly Thanks for the reply. But I am not sure how this works.

Swing in the sense like If you check the below image, like this. If anybody could help me with a example capx, truly thanks.
You do not have the required permissions to view the files attached to this post.
B
7
S
1
Posts: 51
Reputation: 507

### » Wed Feb 04, 2015 4:49 pm

> @animator :

Your question is a bit complex, because the solution depends on how you solve the ball.

Physical concept:

To make a ball drift in a curve, you need to hit it off-center (can be also angled). It gets a spin through that. The spin causes the sideways-offset, since the air flowing around the ball has different speeds (thus density) on each side, so like a plane takes off, the ball goes sideways, because of air pressure differences. The bigger the rotation, the stronger the curve. (If there is no wind and you hit the ball in the middle it will not spin much, and you shoot quite straight.)

So you could detect an offset of the hit from the center-point of the ball - the more offset, the more you let the ball fly sideways (You can also give it a rotation speed according to that, if you want realism.).

The only question is, how you let the ball fly? A behavior?
B
8
S
3
Posts: 197
Reputation: 1,207

### » Wed Feb 04, 2015 9:10 pm

Use qarp to make the ball move in curve, but you must specify the points first. You also need to measure relative distance to the target, I suggest using iterative value from variable that simulate relative 3d distance on spacial 2D.
B
136
S
56
G
24
Posts: 812
Reputation: 24,617

### » Thu Feb 05, 2015 2:17 am

@MultipleChoice The ball has to fly based on the swipe speed - may be physics behavior (I am really not sure yet)

@alextro seems like freaking hard to do uh?
B
7
S
1
Posts: 51
Reputation: 507

### » Thu Feb 05, 2015 4:40 am

u can also use try arc, and radius or try with number variable, recording the highest pick of the X of the mouse or touch and lowest X of mouse or touch
EX: LowXt (number) give property to save the X of touch only when X of touch is lower then initial X touch [first click on ball ]

MaxXt (number) give property to save the x of touch only when x of touch is higher then initial Xtouch (you need a number variable for initial touch or mouse click when u click and drag the mouse call it Initialtouch lets say)

this way u create a 3 way point, then u just use force push towards MaxXt once X of ball is = or > then maxxt force push towards lowXt and try add a delay of movement and an always rotate angle to the next way point " that way the ball will rotate toward the position u swiped i think will work logically will , hope makes sense to u if its sloppy its because im sleepy and im coding for like 48 hrs straight listening to frekain boring adventure 8 bit music on loop for some reason .... cheers and good luck
Do you have games and want to make money with them!? do you want more then pennis from ads you have in your games?! visit us today www.gcstudio.net and make money with your games!:)
B
16
S
2
Posts: 89
Reputation: 2,465

### » Thu Feb 05, 2015 6:47 am

@gamecorptm lol, thanks for the idea though. I will try these ideas now, but not sure coz it seems complicated.

Anyway let me try first
B
7
S
1
Posts: 51
Reputation: 507

### » Thu Feb 05, 2015 8:29 am

Ahh, I was running through the forums searching for examples for this. How to throw a ball forward -

I have found this post and a sample capx. - This is a example for paper toss where the paper flies up and falls down. But in football free kick ball moves forward quickly towards the net with swing.

scirra.com/forum/viewtopic.php?f=147&t=106610&p=789849&hilit=paper+toss#p789849 - Just go to Page 2

As C2 is not in 3D, the game has to be coded in the way that after paper flying to a certain level, there is a sprite(when the paper overlaps this sprite), reduce the paper size a bit to show it is moving forward.

Is there any other way to do this? Applying physics behavior to the ball is fine but how to create the swing?

-------------

Edited:

C2 experts kindly help me with a sample file for throwing a ball forward. It would be nice if scirra has a example for this. I am damn sure it will not only help me
B
7
S
1
Posts: 51
Reputation: 507

### » Thu Feb 05, 2015 10:38 am

yea there is that plugin from rainbow ... he has the swing done long time ago managed to find a link there

scirra.com/forum/behavior-swing_t64261?&hilit=swing
Do you have games and want to make money with them!? do you want more then pennis from ads you have in your games?! visit us today www.gcstudio.net and make money with your games!:)
B
16
S
2
Posts: 89
Reputation: 2,465

Next

Return to How do I....?

### Who is online

Users browsing this forum: dioking, JayH, OddConfection, urkokan and 20 guests