How do I move along a curve?

Get help using Construct 2

Post » Thu Mar 19, 2015 8:49 am

Hello to all, i have actually in my scene differents sprites, who move from outside the frame, to the center of the scene.
Actually my sprites are moving from point to point (picture 1)

I would like to make the sprites moving in a curve (picture 2) how to achieve that??

picture:
Image
B
27
S
10
G
6
Posts: 1,496
Reputation: 7,984

Post » Thu Mar 19, 2015 10:18 am

Hey imothep85, :)
... imothep ... imothep ... imothep ...

One possible method:
Assuming the sprite objects are already set up to move forwards, (e.g. they have "Bullet" behavior or something), you can set their angle each tick to make them approach a target on a spiral path.

Every tick:
  • Set the sprite angle to face the target position.
  • Rotate the sprite 20 degrees clockwise.
Note: Rotating 0 degrees would make the sprite move straight at the target, 90 degrees is circling the target, and anything between 0 and 90 will spiral towards the target.

The above method results in spirals that get curlier as you get closer to the target. If you want more uniform curvature as the sprites approach, you can set that rotation offset to be dependent on the distance between the sprite and the target. So, when the sprite is far from the target, the rotation offset is large (e.g. 45 degrees), and as the sprite gets close to the target the rotation offset gets smaller (e.g. 10 degrees).



Proportional - (with upper limit)
Rotate the sprite min( 80 , 80 * ( distance( Sprite.X , Sprite.Y , Target.X , Target.Y ) / 400 ) )

Here we scale the rotation offset by the distance to the target, with 400 pixels being the distance where the scaling value equals 1.0 (or 100%). We are scaling the number 80 to act as the rotation offset, and we are capping the maximum rotation offset at 80 as well. We cap the offset so that it doesn't reach or exceed 90 degrees which would cause the sprite to start spiraling away from the target.
Making the cap number smaller will make the maximum turning radius softer. (It should be between 0 and up to but not including 90.)
Making the base rotation offset smaller will make the approach turning radius softer. (It should be between 0 and up to but not including 90.)
Making the distance scale larger will make the curves softer.



ArcTangent
Rotate the sprite atan( distance( Sprite.X , Sprite.Y , Target.X , Target.Y ) / 400 )

This is a slightly simpler expression to write and it doesn't require an artificial cap value, because no matter how big the distance gets, the arc-tangent will never return 90 degrees or more. The 400 in this case is the distance at which the arc-tangent will return 45 degrees.
Making the distance scale larger will make the curves softer.
B
21
S
13
G
8
Posts: 306
Reputation: 5,458

Post » Thu Mar 19, 2015 10:25 am

Thanks a lot im going to try that :D
B
27
S
10
G
6
Posts: 1,496
Reputation: 7,984

Post » Fri Mar 20, 2015 4:39 am

No problem, glad to help. :D
B
21
S
13
G
8
Posts: 306
Reputation: 5,458


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 11 guests