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

Get help using Construct 2

Post » 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)
Image

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
33
S
5
G
1
Posts: 163
Reputation: 2,698

Post » Wed Dec 28, 2016 4:57 pm

You could use and x an y tween using @lunarray litetween behaviour: behavior-litetween_t70700?&hilit=litetween
Image
B
30
S
9
G
3
Posts: 171
Reputation: 3,329

Post » 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
78
S
23
G
69
Posts: 1,353
Reputation: 44,005

Post » 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
94
S
33
G
113
Posts: 5,354
Reputation: 73,269

Post » 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" :D
B
78
S
23
G
69
Posts: 1,353
Reputation: 44,005

Post » 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
33
S
5
G
1
Posts: 163
Reputation: 2,698

Post » 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
33
S
5
G
1
Posts: 163
Reputation: 2,698

Post » 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
78
S
23
G
69
Posts: 1,353
Reputation: 44,005

Post » 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. :o
I must confess I've never studied this qarp expression before. Getting the C2 manual now. Thanks!
B
33
S
5
G
1
Posts: 163
Reputation: 2,698

Post » 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
33
S
5
G
1
Posts: 163
Reputation: 2,698

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests