How do I replicate a penalty kick

Get help using Construct 2

Post » Wed Dec 30, 2015 6:19 am

Hi everyone,

I am trying to replicate the a penalty kick from this game http://bit.ly/1mQaWjw
It seems that the ball get some kind of curve and decrease the size slightly by the time it gets to the goal.

thanks,
B
103
S
40
G
23
Posts: 394
Reputation: 20,537

Post » Wed Dec 30, 2015 7:07 am

no idea friend.. waiting for someone to share the code or capx
B
39
S
11
Posts: 68
Reputation: 2,823

Post » Wed Dec 30, 2015 10:34 am

Basically you want to have a random movement first in x axis within a certaing range, which stops after button press, then the same effect in the y axis, once more stopped on button press. Then you have to tie this movement to a slider on screen. I would add it to a variable, both the values.
Also on key press after the ball is being shot, you need to make a tween movement (the slight curve and decrease in scale) of the ball from the player position to the position of the x,y that remiains after button press, stored in a variable that Ive mentioned above.
Brick by brick, stone by stone.
B
50
S
22
G
13
Posts: 273
Reputation: 10,413

Post » Wed Dec 30, 2015 3:07 pm

I get the idea. The problem is to do the movement.
I started using the behavior moveTo but I can't figure out the curve thing
B
103
S
40
G
23
Posts: 394
Reputation: 20,537

Post » Wed Dec 30, 2015 5:31 pm

I am thinking about something like this:

Image
B
103
S
40
G
23
Posts: 394
Reputation: 20,537

Post » Wed Dec 30, 2015 6:19 pm

There is a behaviour called path to spline or something simillar, search the forums, perphaps its what you are looking for.
Brick by brick, stone by stone.
B
50
S
22
G
13
Posts: 273
Reputation: 10,413

Post » Wed Dec 30, 2015 11:04 pm

It's not so much a curve, it's just perspective. The simplest kind is x/z and y/z, where z if how far into the screen the ball is.

Give the Ball sprite some instance variables called "z", "startX" and "startY". Also you presumably you have the two sprites horizontalSlider and verticalSlider. The events below assume the ball is launched as soon as the layout is run and the sliders are already in place. All the numbers are tweakable.

global number t=0

ball: on created
--- set startX to self.x
--- set startY to self.y

every tick
--- set t to min(t+dt, 1)
--- ball: set z to lerp(1, 10, t)
--- ball: set x to (lerp(self.startX, horizontalSlider.x, t)-screenwidth/2)/self.z + screenwidth/2
--- ball: set y to (lerp(self.startY, verticalSlider.y, t)-screenheight/2)/self.z + screenheight/2
--- ball: set size to (64/self.z, 64/self.z)
B
85
S
27
G
85
Posts: 5,063
Reputation: 57,860

Post » Thu Dec 31, 2015 7:23 pm

@R0J0hound,

You solution is nice but it doesn't apply well to the example in question.
The ball get too small and it doesn't go where it supposed to end.
I sent you a msg with the capx with what I got so far.
B
103
S
40
G
23
Posts: 394
Reputation: 20,537

Post » Thu Dec 31, 2015 7:54 pm

Sorry I can't open the capx you sent me. I don't have the moveto behavior installed.

Edit: I did look at the event sheet xml and it appears you're using a different approach, so I probably won't be much help.
B
85
S
27
G
85
Posts: 5,063
Reputation: 57,860

Post » Sat Jan 02, 2016 4:15 am

@R0J0hound,

Thanks for your help anyway. I appreciate it.
B
103
S
40
G
23
Posts: 394
Reputation: 20,537

Next

Return to How do I....?

Who is online

Users browsing this forum: QuantumMMX and 12 guests