# How do I get an object to follow a curved path.

Get help using Construct 2

### » Thu Aug 03, 2017 3:40 am

Hi,

I am working on a form of path-finding for my game. On a move command, it will calculate a path for the player using "nodes".

What i'm trying to work out is this: my player moves to node 1, and then cuts at a sharp angle to node 2 (following the red path here: http://i.imgur.com/FOgFuOv.png), which looks a bit odd. I am trying to gradually curve the player around objects (using the nodes as a guide) so that the player follows something more like the green path shown in the image, instead.

Can anyone think of a formula/approach to get the player to curve it's position gradually as it approaches a node?
(Using: player.x, player.y, node1.x, node1.y, node2.x, node2.y)

I think the Sine behavior might be of use, but this one's got me stumped.
B
90
S
31
G
11
Posts: 101
Reputation: 11,337

### » Thu Aug 03, 2017 4:16 am

There's these ideas:
viewtopic.php?f=147&t=153545&p=967749&hilit=Catmull+rom#p967749

I'll need to check later to update my links.

The formulas are usually a bit too lengthy to remember.
B
98
S
36
G
131
Posts: 5,521
Reputation: 83,505

### » Thu Aug 03, 2017 4:47 am

B
71
S
22
G
281
Posts: 3,842
Reputation: 154,886

### » Thu Aug 03, 2017 5:43 am

@R0J0hound
@blackhornet

Thanks for the links guys! I came across this page: https://www.particleincell.com/2012/bezier-splines/ and it looks similar to what I need. That said it isn't perfect.

In any case, I think the math involved is beyond me. Even if I were to implement it following the bezier spline method, you'll notice how there is an "unnecessary" curve between the first two nodes: http://i.imgur.com/fULycxI.png

I don't need my object to follow the path perfectly, but rather simply curve around the edges (when closer to the nodes) with the goal of just making the movement smoother, do you know of a simpler way to implement something that can achieve this?
B
90
S
31
G
11
Posts: 101
Reputation: 11,337

### » Thu Aug 03, 2017 4:43 pm

You could just use the "rotate to angle" action to gradually turn to a object. It will be smooth but not symmetrical.
B
98
S
36
G
131
Posts: 5,521
Reputation: 83,505

### » Thu Aug 03, 2017 8:16 pm

Colludium made a very nice behavior:
behavior-tween-tween-js-and-bezier-easing_t187854
B
176
S
50
G
200
Posts: 8,634
Reputation: 124,569

### » Thu Aug 03, 2017 10:03 pm

rexrainbow Has a Spline approach.
behavior-rex-spline_t178563
B
33
S
18
G
29
Posts: 2,493
Reputation: 21,450