# How do I draw a parabola between 2 points?

Get help using Construct 2

### » Thu Feb 11, 2016 6:00 am

There is a lot of good info around on calculating parabolas and the like, but I can't seem to apply it to my specific situation.

Basically, I have two sprites (start & end). I want them to be connected by a loosely hanging wire type of thing.
and I'm not using physics. or plugins.

so basically, I want to draw a droopy line from (start.x,start.y) to (end.x,end.y).
I'd also like to be able to change the length (and thus, the droopiness) of the line.

I'm sure this isn't hard. But my brain just isn't doing it.
B
88
S
43
G
71
Posts: 601
Reputation: 43,669

### » Thu Feb 11, 2016 6:15 pm

@spacedoubt
You can use that Pin behaviour, " Pin to X -> Rope style "?
B
11
S
3
Posts: 277
Reputation: 1,395

### » Thu Feb 11, 2016 6:36 pm

Add a sprite to use as a line, and make it's origin centered on the left. Also make it's height 4 or something, that will be the line thickness. Name the sprite "line".

Then you can use the qarp() expression to do the curve and you could do this:

global number px=0
global number py=0

every tick
--- line: destroy
--- set px to start.x
--- set py to start.y

repeat 100 times
--- create line at (qarp(start.x, (start.x+end.x)/2, end.x, (loopindex+1)/100), qarp(start.y, (start.y+end.y)/2+200, end.y, (loopindex+1)/100)
--- line: set angle toward (px,py)
--- line: set width to distance(self.x,self.y,px,py)
--- set px to line.x
--- set py to line.y
B
100
S
38
G
134
Posts: 5,551
Reputation: 85,315

### » Thu Feb 11, 2016 11:26 pm

@R0J0hound Ah, man! you're a genius!
I had a feeling you'd come through on this one

I was already using a mishmash of different stuff you've posted, but just couldn't quite get it right.
Perfect as usual.

Thanks very much!
B
88
S
43
G
71
Posts: 601
Reputation: 43,669

### » Fri Jul 15, 2016 9:11 am

R0J0hound wrote:Add a sprite to use as a line, and make it's origin centered on the left. Also make it's height 4 or something, that will be the line thickness. Name the sprite "line".

Then you can use the qarp() expression to do the curve and you could do this:

global number px=0
global number py=0

every tick
--- line: destroy
--- set px to start.x
--- set py to start.y

repeat 100 times
--- create line at (qarp(start.x, (start.x+end.x)/2, end.x, (loopindex+1)/100), qarp(start.y, (start.y+end.y)/2+200, end.y, (loopindex+1)/100)
--- line: set angle toward (px,py)
--- line: set width to distance(self.x,self.y,px,py)
--- set px to line.x
--- set py to line.y

it's fantasy! but , it's also executing each tick and such more objects were created ...
B
74
S
26
G
5
Posts: 91
Reputation: 7,434

### » Fri Jul 15, 2016 7:22 pm

@totoyan
The goal is always to first create the effect, and this serves are a good example. Sure you can modify it to reuse the same 100 objects or only running the events when you need to, but that wasn't relevant to the example.
B
100
S
38
G
134
Posts: 5,551
Reputation: 85,315

### » Sat Jul 16, 2016 9:14 am

R0J0hound wrote:@totoyan
The goal is always to first create the effect, and this serves are a good example. Sure you can modify it to reuse the same 100 objects or only running the events when you need to, but that wasn't relevant to the example.

actually i want to make a parabola for the grenade when one object aims on another one before throwing it, so after throwing it, the grenade will move for the parabola.
by the way ,i can know the object and another one's position, and the grenade 's bullet speed, bullet gravity.
can you help me ? thanks a lot!
B
74
S
26
G
5
Posts: 91
Reputation: 7,434

### » Sun Jul 17, 2016 6:02 pm

B
100
S
38
G
134
Posts: 5,551
Reputation: 85,315