# [solved]How do I make elliptical motion with offset?

Get help using Construct 2

### » Thu Feb 12, 2015 10:52 pm

I'm trying to figure how to make ellptical motion in following path:

I've uploaded a .capx here, but it does circular motion, not ellitpical with offset, I'm looking a solution, thanks!
You do not have the required permissions to view the files attached to this post.
Last edited by Joannesalfa on Mon Feb 16, 2015 12:24 am, edited 1 time in total.
B
104
S
29
G
22
Posts: 3,066
Reputation: 24,273

### » Fri Feb 13, 2015 7:50 am

Like this? I'm still on r195 I'll need to upgrade

https://dl.dropboxusercontent.com/u/139 ... cle_e.capx
B
10
S
2
G
1
Posts: 202
Reputation: 1,545

### » Fri Feb 13, 2015 10:09 pm

Are you looking for elliptical motion, or motion along the path in your image there? Both are very different
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,455

### » Fri Feb 13, 2015 10:36 pm

@Noncentz705 @sqiddster the image is clear, I don't need like that:

I had no idea what's name of this form, I would say elliptical motion with offset for top line and bottom line, maybe rectangle with rounded corners
B
104
S
29
G
22
Posts: 3,066
Reputation: 24,273

### » Fri Feb 13, 2015 11:03 pm

i think you could make it using standard "circular" motion with sin and cos and little switch. When object is on top just move it forward and after some time turn on circular motion. After reaching bottom turn it off and let it go forward. Then turn it on again etc.
B
140
S
58
G
37
Posts: 2,549
Reputation: 31,711

### » Fri Feb 13, 2015 11:19 pm

As shinkan, just make the y distance longer than the x.
B
163
S
48
G
100
Posts: 7,443
Reputation: 72,008

### » Sat Feb 14, 2015 8:40 pm

Attached is a exact way to do a rounded path like the op.

Code: Select all
`    * |*  *  *  *  *  *| * *    |                |    **     |       o        |     **     |                |     * *    |                |    *    * |*  *  *  *  *  *| *|     |\               |+-----+ +--------------+ radius       space`

You can think of each piece of the path like a lerp from one point to another.
left side:
x = center.x - space/2 + radius*cos(90+180*t)

top:
x = center.x + 0.5*space*lerp(-1,1, t)

right side:
x = center.x + space/2 + radius*cos(-90+180*t)

bottom:
x = center.x + 0.5*space*lerp(1,-1, t)

where t is a number from 0 to 1.

Now all that needs to be done is depending on the distance traveled choose the correct equations and t value.
distance = speed * time

Next we need to know the lengths of the pieces.
The top and bottom are easy with a length of "space".
The left and right can be found with the following equation:
Which ends up as pi*radius for each.

With the above the total length = 2*pi*radius+2*space

To choose the correct equations we compare the distance traveled,

0 to pi*radius is the left side.

Then we find a t (0..1) value for the side with:
If left then t = distance/pi*radius
If top then t = (distance-pi*radius)/space
If bottom then t = (distance-2*pi*radius+space)/space

As a final step we want it to loop so we can use the % operator with the total length to do that.

If speed is negative then we need to do effectively this:
((a%b)+b)%b

In the capx I used a function for that.
You do not have the required permissions to view the files attached to this post.
B
82
S
26
G
62
Posts: 4,830
Reputation: 45,200

### » Mon Feb 16, 2015 12:24 am

@R0J0hound delivers the classic solution.

Thanks a lot, it's solved now.
B
104
S
29
G
22
Posts: 3,066
Reputation: 24,273