# How do I make a sprite move (A-B) in a variable arch path?

Get help using Construct 2

### » Wed Dec 28, 2016 3:31 pm

I'd like to move a ball with variable speed and arch angle, but it must always get from point A to B, then from B to A. Like a pong, but always hitting the targets (that are not moving, just the ball)

Ive tried with bullet / gravity but sometimes it misses the target. When it hits the target I move bullet speed to -180. Ive added a small variation on bullet angle but it doesnt work.

Could you help with ideas? Any easy way to do it?
Thanks in advance
B
35
S
5
G
1
Posts: 169
Reputation: 2,765

### » Wed Dec 28, 2016 4:57 pm

You could use and x an y tween using @lunarray litetween behaviour: behavior-litetween_t70700?&hilit=litetween
B
34
S
11
G
3
Posts: 191
Reputation: 3,678

### » Wed Dec 28, 2016 5:32 pm

well depends....you can try using the circular motion examples that uses sin/cos functions or the lerp function but then again depends what you want to exactly achieve. wold the ball rotate on both 360 degrees or just above? cause for above i have a capx that can help you, for bellow also the same but youl need to add some conditions to trigger the movement of the mid ball. and then you wont be able to use solids or anything else anymore. but you can add your own event system collision box so its ok either way. but with bullet you should be able to do it, using gravity, it only will need gravity adjustment based on the distance between A and B

here is a circular movement AtoBcapx using the sin/cos
B
86
S
26
G
75
Posts: 1,440
Reputation: 47,810

### » Wed Dec 28, 2016 6:08 pm

If you want parabola movement you could use the qarp() expression

Var t=0

Every tick
--- set t to time%2
--- set t to (t>1)?2-t:t
--- set X to qarp(a.x, (a.x+b.x)/2, b.x, t)
--- set y to qarp(a.y, (a.y+b.y)/2-variance, b.y, t)
B
100
S
38
G
134
Posts: 5,556
Reputation: 85,325

### » Wed Dec 28, 2016 7:57 pm

R0J0hound wrote:If you want parabola movement you could use the qarp() expression

Var t=0

Every tick
--- set t to time%2
--- set t to (t>1)?2-t:t
--- set X to qarp(a.x, (a.x+b.x)/2, b.x, t)
--- set y to qarp(a.y, (a.y+b.y)/2-variance, b.y, t)

that's neat "oh"
B
86
S
26
G
75
Posts: 1,440
Reputation: 47,810

### » Wed Dec 28, 2016 7:59 pm

gameglaux wrote:You could use and x an y tween using @lunarray litetween behaviour: behavior-litetween_t70700?&hilit=litetween

I'll install it, thanks!
B
35
S
5
G
1
Posts: 169
Reputation: 2,765

### » Wed Dec 28, 2016 8:06 pm

gamecorpstudio wrote:well depends....you can try using the circular motion examples that uses sin/cos functions or the lerp function but then again depends what you want to exactly achieve. wold the ball rotate on both 360 degrees or just above? cause for above i have a capx that can help you, for bellow also the same but youl need to add some conditions to trigger the movement of the mid ball. and then you wont be able to use solids or anything else anymore. but you can add your own event system collision box so its ok either way. but with bullet you should be able to do it, using gravity, it only will need gravity adjustment based on the distance between A and B

here is a circular movement AtoBcapx using the sin/cos

Thanks, dude. This capx is a pretty good way to do it.
The objective I want to achieve is like one person kicking the ball to the other, without letting it fall. For it not to be boring, I will random part of the speed, simulating a stronger kick. But I gotta find a way (if using bullet) to make a formula that would adjust gravity vs speed so it can always aim and hit the target.
B
35
S
5
G
1
Posts: 169
Reputation: 2,765

### » Wed Dec 28, 2016 8:14 pm

Scofano wrote:
Thanks, dude.

no problem, however R0j0hound's formula is much better just change the 250 number i added in the capx where is the variance or the curvature point.

r0j0hound A to B QARP movement

you could use instead of the 250 number distance(pA.x,pA.y,pB.x,pB.y)/2 feels more natural.
Last edited by gamecorpstudio on Wed Dec 28, 2016 8:24 pm, edited 1 time in total.
B
86
S
26
G
75
Posts: 1,440
Reputation: 47,810

### » Wed Dec 28, 2016 8:22 pm

R0J0hound wrote:If you want parabola movement you could use the qarp() expression

Var t=0

Every tick
--- set t to time%2
--- set t to (t>1)?2-t:t
--- set X to qarp(a.x, (a.x+b.x)/2, b.x, t)
--- set y to qarp(a.y, (a.y+b.y)/2-variance, b.y, t)

Genius.
I must confess I've never studied this qarp expression before. Getting the C2 manual now. Thanks!
B
35
S
5
G
1
Posts: 169
Reputation: 2,765

### » Wed Dec 28, 2016 8:24 pm

gamecorpstudio wrote:
Scofano wrote:
Thanks, dude.

no problem, however R0j0hound's formula is much better just change the 250 number i added in the capx where is the variance or the curvature point.

r0j0hound A to B QARP movement

Yeah! you guys did it. I tried using sine movement on A and B and it works as well. Fantastic.
Thanks again!
B
35
S
5
G
1
Posts: 169
Reputation: 2,765

Next

Return to How do I....?

### Who is online

Users browsing this forum: No registered users and 6 guests